binding more than one attribute in a facntion
faulkner
faulkner612 at comcast.net
Wed Jul 26 16:01:55 EDT 2006
More information about the Python-list mailing list
Wed Jul 26 16:01:55 EDT 2006
- Previous message (by thread): why is this not working? (nested scope question)
- Next message (by thread): binding more than one attribute in a facntion
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
http://cheeseshop.python.org/pypi/functional learn lisp/scheme! http://cs.wwc.edu/KU/PR/Scheme.html Peter Otten wrote: > linuxnow at gmail.com wrote: > > > I want to have a bound method that "fixes" more than one parmeter of a > > funtion. LEt me post an example. > > > > def f(a, b, c): > > return a + b + c > > > > I can do: > > fplus10 = f(10) > > and then call f with 2 params and it works. > > > > But, how can I fix 2 params: > > fplus10plus20 = f(10,20) > > ignores the second param. > > > > fplus10plus20= fplus10(20) > > does not work either. > > > > Can anybody show what I'm doing wrong? > > 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. > > Peter
- Previous message (by thread): why is this not working? (nested scope question)
- Next message (by thread): binding more than one attribute in a facntion
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list