python 在最后一行追加


2.文本文件的寫入

Python代碼   收藏代碼
  1. import fileinput  
  2.   
  3. file = open("D:\\test.txt", encoding="utf-8",mode="w")  
  4. file.write("朝八晚十\n")  
  5. file.close()  
  6.   
  7. with open("D:\\test.txt", encoding="utf-8",mode="a") as data:  
  8.     data.write("朝九晚五")  

 *mode="w",寫模式,會重寫文件;mode="a",追加模式,會在文件末尾添加數據。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM