编码:
# coding=GBK or # -*- coding: GBK -*- 源码使用GBK编码
# coding=UTF-8 or # -*- coding: UTF-8 -*- 源码使用UTF-8编码
string.encode('GBK/UTF-8') 将string转换成bytes
bytes.decode('GBK/UTF-8') 将bytes转换成string
进制转换
:
int("1010",2)得10 #2进制转为10进制
int("077",8)得63 #8进制转为10进制
int('0xff', 16)得255 #16进制到10进制
bin(0xf)得'0b1111' #16进制到2进制
oct(8)得'010' #10进制到8进制
hex(0b1001)得'0x9' #2进制到16进制
OS模块:
os.path.exists(Path) 是否存在该文件或目录os.path.isdir(Path) 是否存在该目录
os.path.isfile(Path) 是否存在该文件
os.dirlist(Path) 返回该路径下的所有文件和目录名
os.path.abspath(name) 获得绝对路径
os.path.splitext() 分离文件名与扩展名
返回一个tuple类型 ,(filename, extension) 元组
os.path.join(path,name) 连接目录与文件名或目录
os.path.basename(path/abc) 返回文件名 "abc"
os.path.dirname(path) 返回文件路径
os.getcwd() 函数得到当前工作目录
os.listdir() 返回指定目录下的所有文件和目录名
os.chdir() 进入指定目录
os.rename(src , tar) 修改文件名
os.path.relpath(src, start) 从start开始计算相对路径
os.getenv(varname, [value])
返回environment变量varname的值,如果value不存在,默认为None.
os.environ() 系统环境变量字典
print os.environ().keys()
使用命令行:
1. os.system('cmd') 可以用来运行shell命令
2. output = os.popen('cmd')
print output.read() 读出执行命令的输出
3. (status, output) = commands.getstatusoutput('cmd')
print status, output 读出返回值和命令的输出
SYS模块:
GUI布局:
Pack 布局
fill (x,y,both) 填充x和y方向的剩余空间
expand (yes,no) 值为自然数或"yes"时,组件会显示在中心位置,如此时fill为both,则填充其空余的空间。默认值为0
side (top, bottom, left, right) 在父组件上定位,默认为top
Grib 布局 网格布局
sticky(w + s + n + e) 靠紧对齐w, s, n, e为方向
column, row 列,行号,在网格中
columnspan, rowspan 列,行组件间的跨度
ipadx, ipady 组件内填充
padx, pady 组件外填充