读写文本数据
- 读取各种不同编码的文本文件时,使用
rt模式的open()函数
with open('xxx.txt','rt') as f:
# data = f.read()
for line in f:
#process line
pass
打印输出到文件的中
eg : 在 print()函数中指定 file 关键字参数
with open('/Users/yjoqm/billboard.txt', 'w+') as f:
print("hellp yjoqm", file=f)