1、私有变量
Python把以两个或以上下划线字符开头且没有以两个或以上下划线结尾的变量当作私有变量。私有变量会在代码生成之前被转换为长格式(变为公有)。转换机制是这样的:在变量前端插入类名,再在前端加入一个下划线字符。这就是所谓的私有变量轧压(Private name mangling)。
http://blog.csdn.net/carolzhang8406/article/details/6859480
2、运行一个GUI程序之后,关掉,再运行,会出错。
这时,在Console里面del app
,然后就可以正常运行了。
3、zip的作用:
scores = [90, 80, 85, 60]
names = ['Jack', 'Mike', 'Jay', 'Bill']
table = dict(zip(names, scores))
print table
Out[23]: {'Bill': 60, 'Jack': 90, 'Jay': 85, 'Mike': 80}
4、tell(), seek()
tell():返回文件读取指针的位置
seek()的三种模式:
- f.seek(p,0) 移动当文件第p个字节处,绝对位置
- f.seek(p,1) 移动到相对于当前位置之后的p个字节
- f.seek(p,2) 移动到相对文章尾之后的p个字节
例:test.txt内容:
Life is short, you need Python.
Simple is better than complex.
import os
os.getcwd()
Out[28]: 'C:\\Python27\\lib\\site-packages\\xy'
fp = open('test.txt', 'r+', 0)
fp.readline()
Out[38]: 'Life is short, you need Python.\n'
fp.tell()
Out[39]: 33L
fp.seek(10, 1)
fp.readline()
Out[41]: 'better than complex. '