# 写方法1
f = open('tmp.txt','w')
f.write('hello world')
f.close() # 写方法2
with open('tmp.txt','w') as f:
f.write('hello \n word') # 读
with open('tmp.txt', 'r') as f:
print(f.read()) # 逐行读
with open('tmp.txt','r') as f:
for line in f.readlines():
print(line.strip())#strip()去除空行