Sunday, February 4, 2018

Python write to file without overwriting current txt




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.


Answer




Instead of "w" use "a" (append) mode with open function:



with open("games.txt", "a") as text_file:

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...