Save a list to a .txt file and keep them

Question:

I found a way to print the list to a txt file, and it worked for me. Except for one detail,

with open("data.txt", "w") as output:
    output.write(str(list))

When I make a different data entry, new data replaces the old data I entered, I want it not to delete the old data and continue recording new data.

Asked By: erdem.a

||

Answers:

using "w" in the open function will rewrite the complete file so use "a" in the open function which will append the file and you will not lose the original text in the file

Answered By: zainsci
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.