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

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

U have to change the mode for open function to 'a', which is append.

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"))