python 在最后一行追加
2.文本文件的写入
- import fileinput
- file = open("D:\\test.txt", encoding="utf-8",mode="w")
- file.write("朝八晚十\n")
- file.close()
- with open("D:\\test.txt", encoding="utf-8",mode="a") as data:
- data.write("朝九晚五")
*mode="w",写模式,会重写文件;mode="a",追加模式,会在文件末尾添加数据。