Home > curry

curry

Curry is a project mainly written in PYTHON and SHELL, it's free.

Pickle-able partial functions for Python

  • Description "The spice must flow!" In this case, we need functions to sate our addiction.

    curry is a module that allows (almost) arbitrary python functions (with some caveats) to be pickled and remotely executed.

    curry works with both pickle and cPickle python modules.

  • Caveats * Python versions Due to a dependence on the marshal* module, the version of python that unpickles and executes the curried function needs to be the same as the version that pickled the function. See the [[http://docs.python.org/library/marshal][marshal module]] for more details.

* Subclassing While curry.curry looks like function application, it is really a constructor for a class implementing the /call/ method. Due to the way objects are pickled, subclassing curry.curry* is prohibited.

* Recursive currying/partial application Do not try to curry an already curried object or a function obtained from applying functools.partial*.

** Function default parameters In order to avoid problems do not directly specify default keyword arguments.

+BEGIN_SRC python

this is bad, do not do this

def foo(x, y, z=1): pass

+END_SRC

Instead pop the defaults out of the /**kwargs/ dictionary:

+BEGIN_SRC python

this is good, do this

def foo(x, y, **kws): z = kws.pop('z', 1)

+END_SRC

  • Installation

    +BEGIN_SRC bash

    $ python setup.py install

    +END_SRC

  • Example

    +BEGIN_SRC python

    import curry import pickle

    define some function

    def foo(x, y, *kws) z = kws.pop('z', 1) return x y * z

    "I wear a function now. Functions are cool"

    fn = curry.curry(foo, 3, z=9)

    with open('function.pkl', 'w') as fd: pickle.dump(fn, fd)

    with open('function.pkl') as fd: h = pickle.load(fd)

    prints 162

    print h(6)

    +END_SRC

Previous:Digilib