Python写入文件而不覆盖当前的txt

34 python

with open("games.txt", "w") as text_file:
    print(driver.current_url)
    text_file.write(driver.current_url + "\n")
Run Code Online (Sandbox Code Playgroud)

我现在正在使用此代码,但是当它写入文件时,它会覆盖旧内容.如何在不删除已经存在的内容的情况下简单地添加它.

Pau*_* Bu 77

而不是"w"使用"a"(附加)模式与open功能:

with open("games.txt", "a") as text_file:
Run Code Online (Sandbox Code Playgroud)