anonymous functions? class?

Peter Bismuti peterb at cortland.com
Thu Nov 15 14:56:26 EST 2001


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?

Thanks





More information about the Python-list mailing list