anonymous functions,classes?

Robert Nikander nikander at
Wed Nov 14 18:45:59 CET 2001

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


More information about the Python-list mailing list