Append a text to file in Python

This question already has an answer here:

  • How do you append to a file? 8 answers

  • 使用模式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中追加文本到文件