python write to file append

纯净搜索 为您找到 本页 4 条,用时 5.45 秒(数据源:360)

AI 回答 由 glm-4-flash 生成 · 仅供参考,请自行核实
1. 使用`open()`函数打开文件,设置模式为`'a'`表示追加模式。
2. 使用文件对象的`write()`方法写入内容。
3. 使用`close()`方法关闭文件。

代码示例:

with open('example.txt', 'a') as file:
file.write('追加的内容\n')