Let's Talk About Lambda Functions!
Jeremy Bowers
jerf at jerf.org
Sat Jul 27 01:30:28 EDT 2002
On Fri, 26 Jul 2002 16:18:56 -0500, Alex Martelli wrote:
> Robb Shecter wrote:
>
>> But to really answer you - I like lambdas and think lambdas can add
>> clarity because their scope directly reflects their 'scope'. (Make
>> sense?)
>
> Sorry, not to me. Take a typical bug sometimes posted here, such as:
>
> for word in 'fee fie foo fum'.split():
> Button(frame, command=lambda: print word)
>
> The poster is typically nonplusses that all buttons print 'fum'.
Speaking as one who recently posted this, what's the alternative?
for word in 'fee fie foo fum'.split():
def printThing():
print word
Button(frame, printThing)
doesn't work any better, you still need
for word in 'fee fie foo fum'.split():
def printThing(word = word):
print word
Button(frame, printThing)
Lambda wart, or just scoping wart in general?
(And I'll still take the lambda form; the def statement feels wrong here.)
More information about the Python-list
mailing list