python第26篇之--文件IO

来源:互联网 发布:it项目经理岗位职责 编辑:程序博客网 时间:2024/06/08 10:14
#!/usr/bin/pythonpoem = '''programming is funwhen the work is doneif you wanna make your work also fun:usr python!'''f = open('poem.txt','w')f.write(poem)f.closef = 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的文件,内容就是上面 打印出来的内容。