#!/usr/bin/python
poem = '''
programming is fun
when the work is done
if you wanna make your work also fun:
usr 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,end=' ')
f.close()
结果:
ang@ubuntu:a_byte_python->./5file_io.py
programming is fun
when the work is done
if you wanna make your work also fun:
usr python!
当然了也会创建一个poem.txt的文件,内容就是上面 打印出来的内容。