Class Persistence using __dict__
Gene C
gchiaramonte at yahoo.com
Mon Sep 4 16:51:51 EDT 2000
> Usually, when I want to make a class persistent, I just pickle the
> class:
>
> class Test:
>
> def Save(self, fn):
> cPickle.dump(self, open(fn, 'w')
>
But if you do it this way, what is the def of the class method that loads
the pickle?
The following dosen't work. Which is what I tried first before dumping and
loading __dict__.
class Test:
def Load(self, fn):
self = cPickle.load(open(fn, 'r'))
I don't want to do the following since the loading is no longer a method of
the class. (I may want to switch to a database from a pickle someday too.)
t = cPickle.load(open(fn, 'r'))
Gene
More information about the Python-list
mailing list