本文介绍了如何在不覆盖当前内容的情况下写入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
with open("games.txt", "w") as text_file:
print(driver.current_url)
text_file.write(driver.current_url + "\n")
我现在正在使用此代码,但是当它写入文件时,它将覆盖旧内容.我怎么能简单地添加它而不删除已经存在的内容.
I'm using this code right now, but when it writes to the file it overwrites the old content. How can I simply add to it without erasing the content that's already there.
推荐答案
使用 open
函数:
with open("games.txt", "a") as text_file:
这篇关于如何在不覆盖当前内容的情况下写入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!