python 在最后一行追加

2.文本文件的写入

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

 *mode="w",写模式,会重写文件;mode="a",追加模式,会在文件末尾添加数据。

原文地址:https://www.cnblogs.com/zle1992/p/6138125.html