Function question
Scott David Daniels
Scott.Daniels at Acm.Org
Thu Apr 11 02:28:31 EDT 2002
On Tue, 9 Apr 2002 17:22:41 +0000 (UTC), huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) wrote:
> On Sun, 7 Apr 2002 23:55:47 -0500, John <nobody at nobody.com> wrote:
> >...What I want to do is:
> >I want to get 'a' dynamically..
> >But once a value is decided, I want a separate function (say, new_add) that
> >does
> >new_add(b) (equals to) add(a,b)
> >
> >That is, I want the function definition to be dynamic.
> >
> >Would that be possible? Any comment would be greatly appreciated.
>
> The easiest way With Python 2.2:
>
> >>> def f1(a):
> .... def f2(b):
> .... return a+b
> .... return f2
> ....
or check
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52549
for "curry ".
if you have a function qqq(a, b, ...),
nf = curry(qqq,v)
makes nf a function like qqq(b, ...).
The trickiness in curry is coping with some args without knowing
how many args the function is supposed to take.
-Scott
More information about the Python-list
mailing list