在python 3中写入文本文件的末尾

use*_*402 4 python text

我目前正在编写一些需要我记录结果的代码。但是,目前,我使用的代码只是覆盖了文档,而不是添加。我可以写什么来在文本文档的末尾添加一些东西?

ch3*_*3ka 5

打开文件 append mode

open(filename, 'a')
Run Code Online (Sandbox Code Playgroud)


Doo*_*nob 5

只需使用附加模式:

with open('something.txt', 'a') as f:
    f.write('text to be appended')
Run Code Online (Sandbox Code Playgroud)

可以在此处找到文档。