找回密碼
 註冊
搜索
查看: 1076|回復: 0

[教學] python 如何開啟檔案複寫檔案

[複製鏈接]
發表於 2020-11-10 21:36:46 | 顯示全部樓層 |閱讀模式
 
Push to Facebook
  1. #input file
  2. fin = open("data.txt", "rt")
  3. #output file to write the result to
  4. fout = open("out.txt", "wt")
  5. #for each line in the input file
  6. for line in fin:
  7.     #read replace the string and write to output file
  8.     fout.write(line.replace('pyton', 'python'))
  9. #close input and output files
  10. fin.close()
  11. fout.close()
複製代碼


 
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

Archiver|手機版|小黑屋|TShopping

GMT+8, 2025-7-6 08:49 , Processed in 0.024489 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回復 返回頂部 返回列表