[Tutor] my text adventure

Dan Lowe dan at tangledhelix.com
Sun Dec 4 08:24:26 CET 2005


On Dec 3, 2005, at 9:40 PM, david wrote:

> sorry i forgot a subject line. i have looked at the pickle module  
> and was able to pickle world.
> but i can't figure how to restore everything.

import pickle

def save_game(state, filename):
     file = open(filename, 'w')
     pickle.dump(state, file)
     file.close()

def load_game(filename):
     file = open(filename, 'r')
     state = pickle.load(file)
     file.close()
     return state

save_game(world, 'mygame')

world = load_game('mygame')

-- 
logic (n.): the art of being wrong with confidence.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20051204/a3075ed0/attachment.htm


More information about the Tutor mailing list