TShopping

 找回密碼
 註冊
搜索
查看: 791|回復: 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, 2024-4-17 01:51 , Processed in 0.059944 second(s), 23 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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