Pickling Recalcitrance

Fredrik Lundh fredrik at pythonware.com
Mon May 24 16:34:28 EDT 1999


srenner at lycosmail.com wrote:
> "PICKLE INTERFACE  Converts (nearly) arbitrary Python objects to/from
> serialized byte streams."
> 
> What is the (nearly) for? And why does this little caveat crop up
> as follows:
> 
>   File "./Lib/pickle.py", line 406, in save_inst
>     save(stuff)
>   File "./Lib/pickle.py", line 197, in save
>     f(self, object)
>   File "./Lib/pickle.py", line 357, in save_dict
>     save(value)
>   File "./Lib/pickle.py", line 158, in save
>     raise PicklingError, \
> pickle.PicklingError: can't pickle 'instance method' objects
> 
> I should mention that almost all my objects do pickle, and I can look
> closely at those which don't if I know what to look for.

http://www.python.org/doc/current/lib/module-pickle.html
tells you what you can pickle.  everything not in that list
is unpicklable...

in your case, it looks like you have callbacks, or other
'function pointers' in your instances. I'd look for some-
thing like:

    def register(self, callback):
        self.callback = callback # points to code
    def notify(self):
        self.callback()

</F>





More information about the Python-list mailing list