第十章. 输入/输出 1) 文件 poem = '''Programming is fun use Python!''' f = file('poem.txt', 'w') # open for 'w'riting f.write(poem) # write text to file f.close() # close the file 可以使用help(file)来了解详情. 2) 储存器 pickle在文件中储存Python对象,cPickle(C语言,更快) import cP…
2016-04-14 20:55:16 八.模块 简介 前面介绍了如何在程序中定义一次函数而重用代码.在其他程序中重用很多函数,就需要使用模块.模块基本上就是一个包含了所有你定义的函数和变量的文件.模块的文件名必须以py为扩展名. import sys print 'The command line arguments are:' for i in sys.argv: print i print 'The PYTHONPATH is', sys.path 结果: The command line…