YA-Newbie: baffled by deepcopy/pickle issues...
Fred Pacquier
fredp at multimania.com.nospam
Tue Sep 21 12:57:02 EDT 1999
Hi,
I'm working on my first sizable app in Python/wxPython, and I was making
good progress until I hit this snag.
I want to be able to capture (to memory) the state of the app at a given
time and restore it later if need be. Luckily most of that state is
encompassed by a single object, so I thought copy.deepcopy() was going to
be a snap.
Problem is, it only works once. I can save the current state, do a bunch of
things, and go back to the saved state, all right. But if I try to restore
it a second time, or try to save another one, everything goes to hell, as
if the objects were empty.
It's a card game, with the object structure like this :
class Card : usual data attributes (color, rank, source bitmap, etc)
class Stack: mostly a List of Cards, plus a few attributes, and methods
self.Cols : an attribute of the wxFrame, a List of 13 Stacks, which
encapsulates most of the game state.
Then I have methods like:
def Save(self, event):
self.SaveGame = deepcopy(self.Cols)
def Restore(self, event):
self.Cols = deepcopy(self.SaveGame)
All classes are defined at the top-level of the module. At first I thought
I had misunderstood something about the function, so after trying a few
variants I replaced deepcopy by pickle.dump() and pickle.load() with a temp
file on disk. The behaviour is exactly the same, so maybe I have a general
namespace/scope problem here...
Any hints on how to track this one down ? Thanks,
fp
--
YAFAP : http://www.multimania.com/fredp/
More information about the Python-list
mailing list