I'm making a game that saves information such as funds and stuff like that about users in a shelve. That shelve starts out looking something like this:
Userdata = shelve.open('UserData', writeback = True)
Userdata[username]={'funds' = 100,
'highscore' = 0}
The username variable is defined earlier. The shelve has keys that are usernames, and the values are dictionaries with that user's data. And then, I have some in-game variables that correspond to the values stored in the dictionary:
funds = Userdata[username]['funds']
highscore = Userdata[username]['highscore']
The variables in the dictionary get changed as the user changes the in-game values. The names of the variables will always be the same as the corresponding dictionary key. The problem is, I have quite a few variables in the dictionary. I was wondering if there was a way to map the variables to the corresponding keys in the dictionary in a for loop or something, so that I don't have to define every single one? Thanks!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…