字符编码:

  1 8bit=1byte

  2 ASCII:1英文字母=1byte。共计127个。

  3 UNICODE:1汉字=3byte.

  4 UTF-8,可变长编码。汉字1-6,英文字母1个字节。

  5 计算机内存中,统一使用Unicode编码,需保存或传输时,使用UTF-8编码。

  6 ord()获取字符的整数表示。chr()把编码转换为对应的字符

  7 以unicode表示的str可通过encode()方法编码为指定的bytes

>>> 'ABC'.encode('ascii')
b'ABC'

>>> '中文'.encode('utf-8')
b'\xe4\xb8\xad\xe6\x96\x87'

  8 反过来,如果从硬盘或网络读取字节流,读到的是bytes,需变为str,使用decode()

>>> b'ABC'.decode('ascii')
'ABC'
>>> b'\xe4\xb8\xad\xe6\x96\x87'.decode('utf-8')
'中文'

 

 

一 帮助文档

help();帮助函数;help(timeit)
dir();显示成员函数;dir(timeit)
__doc__;查看对象的帮助文档;timeit.__doc__;查看模块,查看方法说明

>>> import timeit
>>> help(timeit)
Help on module timeit:

NAME
timeit - Tool for m

>>> dir(timeit)
['Timer', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_globals', 'default_number', 'default_repeat', 'default_timer', 'dummy_src_name', 'gc', 'itertools', 'main', 'reindent', 'repeat', 'sys', 'template', 'time', 'timeit']

>>> timeit.__doc__     #模块
"Tool for measuring e...n"
>>> timeit.timeit.__doc__    #模块的方法
'Convenience function to create Timer object and call timeit method.'

>>> print(timeit.__doc__)    #美观打印
Tool for measuring execution time of small code snippets.

This module avoids a number of common traps for measuring exe

 

 

二 pyc文件;提高运行速度

1 对于当前调用的主程序不会生成pyc文件

2 以import xxx 或 from xxx import xxx等方式导入主程序的模块才会生成pyc文件

3 每次使用pyc文件时,会根据pyc文件的创建时间和源模块进行对比,如有修改,新创建并覆盖;如无,则直接使用pyc文件代替模块

4 pyc文件同意保存在模块所在目录的_pycache_文件夹内

5 pyc不同于java的字节码

posted on 2018-08-14 16:02  voldermorter  阅读(98)  评论(0)    收藏  举报