首页 > 技术文章 > python的文件操作

zhayunjia 2016-08-19 14:39 原文

写文件:

poem=''' program is fun
       using Python!
'''
f=open('poem.txt','w')
f.write(poem)
f.close()

读文件:

f=open("poem.txt")
while True:
    line=f.readline()
    if len(line)==0:
        break
    print(line)
f.close()

 

推荐阅读