How to create functors?

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Wed Aug 19 09:56:08 EDT 2009


Terry Reedy a écrit :
> Robert Dailey wrote:
> 
>> I'm using Python 2.6. And using the legacy syntax in the lambda does
>> not work either. I want to avoid using a def if possible. Thanks.
> 
> In Python, writing
> 
> name = lambda arg: expr
> 
> instead of
> 
> def name(arg): return expr
> 
> is all negative and no positive and should be avoided.

Except that def is a statement, and as such can't be used as a named 
params when calling a function expecting a callback, ie:

vroom = some_dead('parrot', name=lambda arg: exp)

(notice the 'name = lambda arg: exp' ?-)

Ok, nitpicking. Me --->[]

<g>



More information about the Python-list mailing list