anonymous functions,classes?

Robert Nikander nikander at mindspring.com
Wed Nov 14 12:45:59 EST 2001


In article <3bf2a42f$1 at 207.229.64.20>, "Peter Bismuti"
<peterb at cortland.com> 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)
> 

Someone already mentioned lambda expressions, which should work if your
function is just a simple thing.  If if you are creating alot of these
little functions and they all follow a certain pattern, you might want to
write a class and define it's __call__(self, ...)  method.  Then you could

callFunction( CallableObject(args) )

Rob



More information about the Python-list mailing list