文件-讀、寫、追加已經文件操作

  讀文件:r f=open('test.txt',mode='r') for line in f: print(line) f.close() print本身會換行,文本自帶一個\n,所以有換行 二進制讀取:rb 寫文件:w,w會創建新文件,有同名則刪除內容再寫入 f=open('test1.txt',mode='w',encoding="gbk") #unicode會自動轉碼位gbk
相關文章
相關標籤/搜索