讀寫文本數(shù)據(jù)
- 讀取各種不同編碼的文本文件時(shí),使用
rt模式的open()函數(shù)
with open('xxx.txt','rt') as f:
# data = f.read()
for line in f:
#process line
pass
打印輸出到文件的中
eg : 在 print()函數(shù)中指定 file 關(guān)鍵字參數(shù)
with open('/Users/yjoqm/billboard.txt', 'w+') as f:
print("hellp yjoqm", file=f)