Moving class used in pickle
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Mon May 21 20:40:49 EDT 2007
En Mon, 21 May 2007 16:24:55 -0300, Berthold Höllmann
<bhoel at despammed.com> escribió:
> Jeffrey Barish <jeff_barish at earthlink.net> writes:
>
>> I have a class derived from string that is used in a pickle. In the new
>> version of my program, I moved the module containing the definition of
>> the class. Now the unpickle fails because it doesn't find the module.
>> I
>
> You can fiddle with the file class used reading the pickled file. I.e.
> the "read()" method could replace each instance of "foo.myclass" by
> "greatnewmodule.mynewclass" could bring you back in the game.
There is a hook in the pickle module (load_global or find_global) that you
can override instead, and it's exactly for this usage, see:
http://docs.python.org/lib/pickle-sub.html
--
Gabriel Genellina
More information about the Python-list
mailing list