标签: python
with open("games.txt", "w") as text_file: print(driver.current_url) text_file.write(driver.current_url + "\n")
我现在正在使用此代码,但是当它写入文件时,它会覆盖旧内容。如何在不删除已经存在的内容的情况下简单地添加它。
答案 0 :(得分:67)
而不是"w"使用"a"(追加)模式与open函数:
"w"
"a"
open
with open("games.txt", "a") as text_file: