method = Klass.othermethod considered PITA

John J. Lee jjl at pobox.com
Tue Jun 7 19:15:54 EDT 2005


Steven Bethard <steven.bethard at gmail.com> writes:
> John J. Lee wrote:
> > Steven Bethard <steven.bethard at gmail.com> writes:
> >>In Python 2.4:
> >>
> >>py> class A(object):
> >>...     def foo(self):
> >>...         print 'foo'
> >>...     bar = foo
> >>...
> >>py> import pickle
> >>py> pickle.loads(pickle.dumps(A)).bar
> >><unbound method A.foo>
> >>py> pickle.loads(pickle.dumps(A())).bar()
> >>foo
> > I meant class instances.
> 
> Look closer.  The second example pickles and unpickles an instance of
> class A.

Oh, I guess it was functions as *instance* attributes that mess up
pickle.


John



More information about the Python-list mailing list