Let's Talk About Lambda Functions!
johnroth at ameritech.net
Fri Aug 2 14:01:50 CEST 2002
"Greg Ewing" <see_reply_address at something.invalid> wrote in message
news:3D49E138.80202 at something.invalid...
> John Roth wrote:
> >>>>In fact, you can even do:
> >>>>class X:
> >>>> func = lambda self, x: x * 2
> >>>Unfortunately, that won't work. The word 'self' is not
> >>>magic - using it doesn't convert a function to a method.
> >>No, but making it a class attribute seems to do the magic
> >>(which can also be modified with staticmethod and classmethod).
> > Yes, but that's the exact problem. Methods become such by
> > being directly under the class definition.
> No, they don't! They become methods by being builtin
> function objects and getting found in the class namespace
> during an attribute lookup. Where abouts the definition
> was originally written doesn't come into it.
Interesting! So an anonymous def is necessarily
In other words,
bar = (
def (x, y):
makes the anonymous function a method because it's
bound to a name in the class namespace? (I'm using
Bengt Richter's suggested syntax here, rather than my
original suggestion, btw.)
More information about the Python-list