Pickle, __init__, and classes

Yin yin_12180 at yahoo.com
Tue Aug 2 16:10:24 EDT 2005


I've created a class that reads in and processes a file in the
initializer __init__.  The processing is fairly substantial, and thus,
instead of processing the file every time the object is created, I
pickle the object to a file.

In subsequent creations of the object, I implement a test to see
whether the pickled file exists.  If it does, then I unpickle the
object.

Unfortunately, the __init__ cannot return this unpickled object.

I've used an auxiliary member function which fixes the problem, but I
would prefer to have the correct object returned at instantiation
rather than returned from the auxiliary member function.

Are there other ways of approaching this problem?

Thanks,
Yin




More information about the Python-list mailing list