annonymous functions -- how to

Fredrik Lundh fredrik at pythonware.com
Fri May 6 13:18:07 EDT 2005


Dave Benjamin wrote:

> > 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.

"I don't wanna try that", you mean.

because if you had done so, you would have noticed that "multiple
functions with the same name" doesn't have to be any more confusing
than "multiple print statements" or "multiple if statements" (as long as
you're not using bad names on purpose, of course).

> > there's also:
> >
> >     def add_thingy(self):
>
> What object is "self"? Are we defining a method at this point?

if you have a problem with methods, you shouldn't use Python.

>
> >         yield get_new_thingy_id; thingy_id = self.result
>
> What is "get_new_thingy_id"? A function? To whom are we yielding here?

I could have sworn that you mentioned event-driven programming
in your original post.  if that's still what you're doing, the answers
are "a token" and "the event source".

</F>






More information about the Python-list mailing list