anonymous functions? class?

Steve Holden sholden at holdenweb.com
Thu Nov 15 21:34:55 CET 2001


[posted & mailed]

"Peter Bismuti" <peterb at cortland.com> wrote in ...
> I want to pass a function as an argument but don't want to have to define
it
> globally.
> I think the proper terminology for this is "anonymous".
>
> The way I *don't* want to do it:
>
> def foo():
>     pass
> callFunction(foo)
>
> The way I want to do it:
>
> callFunction(def foo(): pass)
>
>
> I'm guessing this can't be done because of Python's indenting syntax.
> In ECMAscript you can send a function as an argument that is defined on
the
> fly such as:
>
> callMyFunction( new Function(){ blah blah })
>
> Something like that. Here the function has not been named and was not
> defined outside of the call.   Can this be done in Python?
>
Peter:

The answer is the same as yesterday: you must either define a function or
use a lambda. Didn't you see all those posts in reponse to your previous
questions?

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list