[wxPython-users] Trouble using lambda to pass args to event function

Christopher Barker Chris.Barker at noaa.gov
Wed Nov 29 14:41:58 PST 2006


Peter Hansen wrote:
> Better in several (small) ways.  Some people just don't find lambda 
> particularly readable, perhaps because of those commas and colons in odd 
> places.

true.

>  For example, I find it next to impossible to parse the above 
> line with lambda.  (Fortunately the Python parser is smarter than I am.)

> Some people also feel that using lambda simply to get the side effects 
> of calling a function is abusing it.  You aren't using the return value 
> of the lambda call at all,

yes, this does use it, it's not just side effects. lambda returns a 
function -- that function is being passed in as the callback, just like 
it should, and just like partial(). The only "side-effect-y thing here 
is the "keyword argument evaluation trick", which you need for the 
"partial" approach too.

That being said, while I think partial() is only slightly better in this 
case, it is more flexible in general, and pretty darn cool.

thanks for the tip.

-Chris

-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov




More information about the wxpython-users mailing list