python 读写本地数据

来源:互联网 发布:和前任做朋友 知乎 编辑:程序博客网 时间:2024/05/16 11:35
f = open(r'C:\Users\kaidi\Documents\GitHub\MyPythonTest\firststep.txt','w')f.write('Hello! How are u?')f.close()f = open(r'C:\Users\kaidi\Documents\GitHub\MyPythonTest\firststep.txt','r')F1 = f.read(5)F2 = f.read()#Read the reat of the txtf.close()print F2

结果输出为一整行。f.write()不会自动换行。需要显示添加 f.write('\n')
0 0
原创粉丝点击