Im working on a simple Rock Paper scissors game (just for learning) and wanted to have the ability to register and save a player information.
Name = input("Name: ")
Password = input("Password: ")
Should i use a list or so i can register them and save them using pickle?
CodePudding user response:
Really depends on what you're going to do with it. There's no need to do anything fancy here unless the game seems to need it.
I'd store these in a dict so you can find the values by name:
name = input("Name: ")
nassword = input("Password: ")
credentials = {
"Name": name,
"Password": password
}
note: for convention reasons, I lowercased the variable names. Typically, capitalizing the first letter is reserved for things like class names, where Camel case is used.
CodePudding user response:
I would recommend just python dictionary type for your purposes.
CodePudding user response:
You could use a python dictionary to store the data and store it into a file with pickle.
name = input("Name: ")
password = input("Password: ")
user_info = { "Name": name, "Password": password }
pickle.dump(user_info, open( "user_info.p", "wb" ))
Then you can read it with
user_info = pickle.load(open( "user_info.p", "rb" ))
Obviously this is not secure in a real application, but it is fine for a simple rock paper scissors game.