Append a text to file in Python
This question already has an answer here:
使用模式a
而不是w
追加到文件中:
with open('text.txt', 'a', encoding='utf-8') as file:
file.write('Spam and eggs!')
As for your first question, googling will turn up several ways. Try this earlier SO question:
Pythonic way to test if a file exists?
链接地址: http://www.djcxy.com/p/42394.html上一篇: 在第一个空行写入CSV
下一篇: 在Python中追加文本到文件