Ask coding questions

← Back to all posts
Why is my text file resetting?
annah2 (0)

Every time that I run my program and go through it the password in the OldPasswords text file is deleted and replaced I would like it to just add the new password in the same line of the text file
https://repl.it/@annah2/Passwords-with-files

Answered by leon332157 (217) [earned 5 cycles]
View Answer
Commentshotnewtop
leon332157 (217)

U have to change the mode for open function to 'a', which is append.
https://docs.python.org/3.7/tutorial/inputoutput.html

timmy_i_chen (1129)

Writing to a file will overwrite it, I think you wanted to open it in append mode instead of write mode. (open("test.txt", "a") instead of open("test.txt", "w"))