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

Steve Waterbury waterbug at beeblebrox.gsfc.nasa.gov
Tue Nov 12 12:06:07 EST 2002

Twisted Gurus:

I'm using the "curry" recipe from the Python Cookbook 
(pretty much verbatim), and it appears to work fine in my 
code, but cPickle isn't happy about it:

Traceback (most recent call last):
  File "/usr/local/bin/mktap", line 31, in ?
  File "/usr/local/lib/python2.2/site-packages/twisted/scripts/mktap.py", line 180, in run
  File "/usr/local/lib/python2.2/site-packages/twisted/internet/app.py", line 508, in save
    dumpFunc(self, f)
  File "/usr/local/lib/python2.2/site-packages/twisted/internet/app.py", line 490, in dumpFunc
    _dump(obj, file, 1)
cPickle.PicklingError: Can't pickle <function curried_function at 0x83a2aa4>: it's not found as __main__.curried_function


Here is the recipe I'm using:

def curry(*args, **create_time_kwds):
    Currying is a way to bind arguments with a function and
    wait for the rest of the arguments to show up later.  You
    "curry in" the first few parameters to a function, giving you
    a function that takes subsequent parameters as input and
    calls the original with all of those parameters.

    Nick Perkins' latest version of curry-by-closure (from
    c.l.p, for the record) It has curry-from-left (for positional
    args) and call-time-dominates (for named args) semantics
    func = args[0]
    create_time_args = args[1:]
    def curried_function(*call_time_args, **call_time_kwds):
        args = create_time_args + call_time_args
        kwds = create_time_kwds.copy()
        return func(*args, **kwds)
    return curried_function


Any ideas?

-- Steve.

More information about the Twisted-Python mailing list