标签:
打开文件并写内容:
# _*_ coding: gbk _*_ # 打开一个文件 fo = open("foo.txt", "wb") fo.write (("Python isia great language.\nYeah its great!!\n").encode()) #注意上面的内容添加encode()否则报错:TypeError: ‘str‘ does not support the buffer interface # 关闭打开的文件 fo.close()
打开文件并读内容:
fo = open("foo.txt", "r+") str = fo.read(10); print ("Read String is : ", str) # 关闭打开的文件 fo.close()
http://www.w3cschool.cc/python/python-files-io.html
标签:
原文地址:http://www.cnblogs.com/lwngreat/p/4186699.html