anonymous functions,classes?

Peter Hansen peter at engcorp.com
Thu Nov 15 00:28:22 EST 2001


Peter Bismuti wrote:
> 
> Anonymous was the word I was looking for in my previous post.  I want to
> pass a function as an argument but don't want to have to define it globally.
> 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)

Although I can't think why you would want to do this, technically
the following ends up with roughly the same effect:

def foo():
    pass

callFunction(foo)

del foo

At least, by the time the del executes, the situation looks
the same as it does after your version, except for the
temporary use of the name foo...

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list