binding more than one attribute in a facntion

linuxnow at gmail.com linuxnow at gmail.com
Thu Jul 27 02:00:05 EDT 2006


Peter Otten wrote:
> linuxnow at gmail.com wrote:

> Bound methods are limited to one implicit parameter. What you need is
> partial function application:
>
> >>> def f(a, b, c):
> ...     return a + b + c
> ...
> >>> def partial(f, *args):
> ...     def g(*more):
> ...             return f(*args+more)
> ...     return g
> ...
> >>> partial(f, 1, 2)(3)
> 6
> >>> partial(f, 1)(2, 3)
> 6
> >>> partial(f)(1, 2, 3)
> 6
>
> See http://www.python.org/dev/peps/pep-0309/ for more.

Thanks, this explanation is great. Nice to see also that python 2.5
will have it,




More information about the Python-list mailing list