【发布时间】:2014-04-21 22:00:03
【问题描述】:
with open("games.txt", "w") as text_file:
print(driver.current_url)
text_file.write(driver.current_url + "\n")
我现在正在使用此代码,但是当它写入文件时会覆盖旧内容。我怎样才能简单地添加它而不删除已经存在的内容。
【问题讨论】:
with open("games.txt", "w") as text_file:
print(driver.current_url)
text_file.write(driver.current_url + "\n")
我现在正在使用此代码,但是当它写入文件时会覆盖旧内容。我怎样才能简单地添加它而不删除已经存在的内容。
【问题讨论】:
使用"a"(附加)模式和open 函数代替"w":
with open("games.txt", "a") as text_file:
【讨论】: