getstate, setstate and pickle
Emile van Sebille
emile at fenx.com
Thu Jun 24 15:51:56 EDT 1999
I've written a class, instantiated, then pickled the instance. At
first, pickling wouldn't work at all, but through some mix of
eliminating a class variable 'id' and adding __setstate__ and
__getstate__ methods it does dump (too soon to call it a pickle).
What I'm having trouble with is getting the load to match the dump. I
lifted parts of the pickle module test code, and the dump == load part
fails, then my code falls apart, and then nothing works... (I'm in
California, so picking grapes is an option ;-)
I'm probably not using get/set state properly. My instance should be
pickleable or I'd get an error there.
Any help or pointers to examples/docs appreciated.
--
Emile van Sebille
emile at fenx.com
NB: Perhaps builtins could be honorably mentioned along with reserved
words in the documentation. I'm now typing type(target) to get the
error as a result of my id problem above. In time, I'll know them. But
for now, it wasn't a pleasant bug to chase.
-------------------
More information about the Python-list
mailing list