Why can't instance methods be pickled?

Nicholas K. Sauter nksauter at lbl.gov
Fri Oct 6 18:57:57 EDT 2000


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nksauter.vcf
Type: text/x-vcard
Size: 367 bytes
Desc: Card for Nicholas K. Sauter
URL: <http://mail.python.org/pipermail/python-list/attachments/20001006/163e8f80/attachment.vcf>


More information about the Python-list mailing list