#!/usr/bin/python
# Filename: file_io.py
poem = '''\
Programming is fun
When the work is done
if you wanna make your work also fun:
use Python!
'''
with open('poem.txt', 'w', encoding="utf-8") as f: # 写模式打开
f.write(poem) # 写文件
with open('poem.txt', encoding="utf-8") as f: # 如果没有提供打开模式, 则默认假设为读模式
while True:
line = f.readline()
if not line:
break
print(line, end='')