python的文件操作

写文件:

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()

 

posted @ 2016-08-19 14:39  苦力劳动者  阅读(134)  评论(0编辑  收藏  举报