Using pickle with setattr

Josiah Carlson jcarlson at uci.edu
Fri Oct 15 02:30:36 CEST 2004


> I'm flabbergasted. Nobody on the python mailing list knows? I've stumped 
> the experts? ;)
> 
> Or maybe my question is stupid for somer reason? :P

Let us try it out:

>>> import pickle
>>> def fun(*args):
...     pass
...
>>> class foo:
...     pass
...
>>> pickle.dumps(foo(), 0)
'(i__main__\nfoo\np0\n(dp1\nb.'
>>> foo.fun = fun
>>> foo().fun()
>>> pickle.dumps(foo(), 0)
'(i__main__\nfoo\np0\n(dp1\nb.'
>>>

It doesn't look any different to me.

Try using it wherever you want.  If it fails at some point or another,
let us know.

 - Josiah




More information about the Python-list mailing list