Class Persistence using __dict__
gchiaramonte at yahoo.com
Tue Sep 5 01:55:51 CEST 2000
I think I'll just stick with pickling __dict__.
> If you're bent on doing it in the context of the class, you could do
> something like this, I guess:
> class Test:
> def __init__(self, **kw):
> if kw.has_key('pickle_filename'):
> # 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.
More information about the Python-list