Class Persistence using __dict__
cut_me_out at hotmail.com
Mon Sep 4 23:19:50 CEST 2000
> But if you do it this way, what is the def of the class method that
> loads the pickle?
Well, I have a helper function that does the loading for me. Something
If you're bent on doing it in the context of the class, you could do
something like this, I guess:
def __init__(self, **kw):
# Load data in from a pickle.
pickle = cPickle.load(kw['pickle_filename'])
for attr in dir(pickle):
# Transfer the attributes of the pickle to this instance
setattr(self, attr, getattr(pickle, attr))
# Do your usual initialization here.
t = Test(pickle_filename=fn)
...but it seems a little awkward to me.
The chain of destiny can only be grasped one link at a time.
-- Sir Winston Churchill
More information about the Python-list