469,343 Members | 5,395 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

Pickle question

Hi,

Can I force the pickling/unpickling mechanism to call the class
constructor? I thought __getinitargs__ would do the job, but the
following shows it does not.
class Test(object): def __init__(self, **kwargs):
super(Test, self).__init__(**kwargs)
self.__dict__.update(kwargs)
def __getinitargs__(self):
print "Calling __getinitargs__."
return ()
def __getattr__(self, attrib):
print "Getting %s." % attrib
raise AttributeError

a = Test(name = None)
s = pickle.dumps(a) Getting __getstate__.
Getting __slots__. b = pickle.loads(s) Getting __setstate__.


I thought unpickling with __getinitargs__ present would go as:

1. Call class constructor with args read from pickle and return inst.
2. Update inst by either calling __setstate__ (if there is) or just
update inst.__dict__.

What am I missing?

With my best regards,
G. Rodrigues
Jul 18 '05 #1
0 1049

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.