Pochemu open('file.txt', 'r') udalaet of the contents of the file?

signup_q = input("You logged in ? Y/N")
if signup_q == 'Y':
 signup = open('login.txt', 'r')
 login = signup.readline().split(':')[1]
print(login)
 login = login[1]
 password = signup.readline().split(':')[1]
 if login == " or passwoed == ":
 print('You have deceived me, you are not logged in!')
 signup_q = 'N'
signup.close()
if signup_q == 'N':
 login = input('Enter the username')
 password = input('Enter the password')
 if input('You remember? Y/N') == 'Y':
 signup = open('login.txt', 'w')
signup.write('login:'+login+'\n')
signup.write('password:'+password+'\n')
signup.close()

print(login, password)

Design recording works fine, the entry in the file is. But when I try
signup = open('login.txt', 'r')
The contents are erased, why?
March 19th 20 at 08:27
1 answer
March 19th 20 at 08:29
Solution
with open("test.txt", "a") as myfile:
myfile.write("appended text")


For example.

Find more questions by tags Python