I am new to python trying to write a very simple game with simple login system to save progression later on.
I am doing User objects for login and storing in list, but list is empty on program exit, this is what I've written
class Users(object):
users = []
def __init__(self, username=None, password=None):
global users #recommended from comment on this website other topic
self.username = username
self.password = password
#print Users.users[0].username #was using to check if object saved to list
#print Users.users[0].password
print "L to login, R to register, Q to quit"
answer = raw_input("> ")
if answer == "r":
username_r = raw_input("Create name: ")
for user in Users.users:
if username_r in user.username:
#if any (self.username == username_r for Users in Users.users):
print "Name already exists"
password_r = raw_input("Create password: ")
u = Users(username_r, password_r)
Users.users.insert(len(Users.users), u)
print "\n------------------\n"
print Users.users[0].username #appends correctly
print Users.users[0].password
I have tried and read other code from website but it does not store in list permanently to access later on.
This code is only introduction for game, user opens and he is asked to login or register to start.
Using notepad++ and powershell, any help is greatly appreciated, thank you.