Using lambda [was Re: Article of interest: Python pros/cons for theenterprise]

Duncan Booth duncan.booth at invalid.invalid
Mon Feb 25 11:03:03 EST 2008


Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> wrote:

>> but if
>> you pass functions/lambdas around a lot it can be frustrating when you
>> get an error such as:
>> 
>>     TypeError: <lambda>() takes exactly 2 arguments (1 given)
>> 
>> and the traceback only tells you which line generated the TypeError, not
>> which lambda was involved. On the other hand:
> 
> In the simple cases I'm talking about, there is only one lambda in scope 
> at a time. If that were not the case, I'd use def.
> 
In the fictional example you gave there are potentially two lambdas: the 
one passed in or the default one.

I use lambda quite often myself, but I do feel that if you do have a name 
for the function then you might as well tell the function what it's called. 
It probably won't matter, but it doesn't hurt you (2 extra characters to 
type), and it might just save you grief further down the line. Each to his 
own though.



More information about the Python-list mailing list