I wrote a code to create a user and login but the created user will be in memory only till the program is running and when the program closes then the user gets destroyed. Now if I decide to store the username and password to a file, then how can I do so in the below python code.I just want to store it to a file not to read or compare it yet. And I just started learning Python so don't know anything advance or any tricky terms.
Edit: I am unable to write the username and password to the file.
users = {}
status = ""
f = open('E:\\login_try2.txt','w')
def displayMenu():
status = input("Are you registered user? y/n/q ")
if status == "y":
oldUser()
elif status == "n":
newUser()
elif status == "q":
exitCode()
def exitCode():
exit()
def newUser():
username = input("Enter username: ")
f.write(username)
if username in users:
print("\nUsername already exists!\n")
else:
password = input("Create Password: ")
users[username] = password
f.write(password)
print("\nUser created\n")
def oldUser():
login = input("Enter username: ")
passw = input("Enter password: ")
if login in users and users[login] == passw:
print("\nLogin Successful!\n")
else:
print("\nUser doesnt exist or wrong password!\n")
while status != "q":
displayMenu()
f.close()