annonymous functions -- how to

Dave Benjamin dave.benjamin at gmail.com
Fri May 6 12:50:53 EDT 2005


Fredrik Lundh wrote:
> Dave Benjamin wrote:
> 
>>In this case, having to name these callback functions is tiring and
>>awkward, and (IMHO) disrupts the flow of my function:
> 
> so name them all "func" or "next" or something, so you don't have
> to think.  once the object is bound, the name is irrlevant.

Sure, you could do this, but then you'd have multiple functions at 
different nesting levels with the same name, which would be confusing. 
You could call them "func1", "func2", "func3", and so on, but at this 
point it becomes painfully obvious that you really don't care what the 
names are; you're only naming them because you have to. As Paul Graham 
would say, it's "the human compiler at work".

> there's also:
> 
>     def add_thingy(self):

What object is "self"? Are we defining a method at this point?

>         yield get_new_thingy_id; thingy_id = self.result

What is "get_new_thingy_id"? A function? To whom are we yielding here?

Dave



More information about the Python-list mailing list