Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Game variables are stored in a dictionary:
- game_data = {"pNev" : "Inid",
- "pKaszt" : 1,
- "pEro" : 12,
- "pElet" : 550,
- "pUgyesseg" : 5,
- "pErtelem" : 1,
- "pStamina" : 25,
- "pCelzas" : 1,
- "pPenz" : 2,
- "pSzint" : 4,
- "pExp" : 199,
- "kepesPont" : 1
- }
- # Get a list of variables:
- print ", ".join(game_data.keys())
- # Access the value of a variable:
- print game_data["pExp"]
- # modifying a variable:
- game_data["pExp"] += 1
- # Access a variable again:
- print game_data["pExp"]
- # Saving data into a file in JSON format:
- import json
- with open('mentes.txt', 'w') as outfile:
- json.dump(game_data, outfile)
- # Reading data back from json:
- with open('mentes.txt') as json_data:
- game_data2 = json.load(json_data)
- json_data.close()
- # Now the data is read back in a new dictionary: game_data2
- print game_data2["pExp"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement