Why can't instance methods be pickled?

Curtis Jensen cjensen at bioeng.ucsd.edu
Mon Oct 9 20:39:58 EDT 2000


"Nicholas K. Sauter" wrote:
> 
> Hello all,
>     This very simple example fails because instance methods cannot be
> pickled:
> 
> import pickle,sys
> 
> class foo:
>   def __init__(self):
>     self.advertise = self.message
>   def message(self):
>     print "I am spam"
> 
> f = foo()
> f.advertise()
> pickle.dump(f, sys.stdout)
> #raises a pickle.PicklingError
> 
>     Is there a fundamental reason why instance method pickling is not
> implemented? Has anyone written code to solve this problem?
> 
> Nick Sauter


"Attempts to pickle unpicklable objects will raise the
PicklingError...."
http://www.python.org/doc/current/lib/module-pickle.html

-- 
Curtis Jensen
cjensen at bioeng.ucsd.edu
http://www-bioeng.ucsd.edu/~cjensen/
FAX (425) 740-1451



More information about the Python-list mailing list