python 开发文档镇楼。 https://docs.python.org/2/index.html
关于代码
python的合理布局
(1)起始行
(2) 模块文档
(3)模块导入
(4)变量定义
(5)类定义
(6)函数定义
(7)主程序
文档编码
#encoding: utf-8 # 设置系统编码
import codecs
codecs.open("loc,txt","w","utf-8")
模块的测试
if __name__=="__main__":
test()
系统参数
import sys
sys.argv #argv是一个数组
#你在命令行输入
#>python thisfile.py
#会得到一个元素的数组,数组里面的元素是thisfile.py
python的重定向
import sys
print>>sys.stderr,'error'
logfile=open('a.txt','w')
print>>logfile,'ssss'
logfile.close()
在刚开始的时候命令行输出流重新定向
$ python code.py >>save.txt
时间的显示
import time
time.strftime("%X",time.localtime()) #显示当前时间
import time
t0=time.time()
t1 = time.time()
print(" %.2g sec" % (t1 - t0)) #显示运行时间
基础语法
变量名
python的下划线
XX 表示是系统自带的变量
_XX 表示是类中的私有变量
输入
user=raw_input('enter')
print 'your enter',user
输出
pretty print 冲着这个名字也要用一下啊
https://docs.python.org/2/library/pprint.html
>>> import pprint
>>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
>>> stuff.insert(0, stuff[:])
>>> pp = pprint.PrettyPrinter(indent=4)
>>> pp.pprint(stuff)
[ ['spam', 'eggs',