Reputation: 61
I'm making a Animal guessing game and i finish the program but i want to add pickle so it save questions to disk, so they won't go away when the program exits. Anyone can help?
Upvotes: 5
Views: 5381
Reputation: 930
Save an object containing the game state before the program exits:
pickle.dump(game_state, open('gamestate.pickle', 'wb'))
Load the object when the program is started:
game_state = pickle.load(open('gamestate.pickle', 'rb'))
In your case, game_state may be a list of questions.
Upvotes: 16