[Twisted-Python] Re: pickle apparently doesn't go with curry ...

Michael Hudson mwh at python.net
Wed Nov 13 05:50:50 EST 2002


jml at mumak.net (Jonathan M. Lange) writes:

> >>> def foo():
> =2E..   pass
> =2E..
> >>> import cPickle
> >>> cPickle.dump(foo, open('testpickle', 'w'))
> >>> bar =3D cPickle.load(open('testpickle'))
> 
> I'd imagine this would work in most versions of python, given that
> people have been pickling objects for countless generations.

Oops, my mistake.  But note that whats been pickled is a reference to
__main__.foo, not the function object itself:

$ python2
Python 2.2.1 (#1, Apr  9 2002, 13:10:27) 
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def foo():
...  pass
... 
>>> import pickle
>>> pickle.dump(foo, open("/tmp/t", "w"))
>>> 
$ python2
Python 2.2.1 (#1, Apr  9 2002, 13:10:27) 
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> foo = 1
>>> pickle.load(open("/tmp/t"))
1
>>> 

so 

def f():
    def g():
        return 1
    return g

pickle.dump(f(), ...)

still isn't going to work... (without fiddling).

Cheers,
M.






More information about the Twisted-Python mailing list