multithreading-problem
Scott David Daniels
Scott.Daniels at Acm.Org
Sun Jul 27 19:24:38 EDT 2003
Diez B. Roggisch wrote:
> Ah, ok. That makes sense. Where do I find this curry-function, only in the
> book? It appears not to be a standard function.
Bottom of my message before, just type it in. (or go to ActiveState for
the class-based version).
The cookbook site:
http://aspn.activestate.com/ASPN/Python/Cookbook/
The curry recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52549
-Scott
Example of use in IDLE (followed by code):
>>> from my_util import curry
>>> def f(a,b,c): return a*b+c
>>> g = curry(3)
>>> assert g(2,1) == 7 == f(3,2,1)
>>>
file: my_util.py
from __future__ import nested_scopes
def curry(*_args, **_kwargs):
"""curry(f,<args>)(<more>) == f(<args>, <more>) (roughly).
keyword args in the curry call can be overridden by keyword args
in the later call; curry can be used to change defaults.
"""
def result(*__args, **__kwargs):
if _kwargs and __kwargs:
kwargs = _kwargs.copy()
kwargs.update(__kwargs)
else:
kwargs = _kwargs or __kwargs
return _args[0](*(_args[1:]+__args), **kwargs)
return result
More information about the Python-list
mailing list