Weird lambda behavior

Chris Rebert clp2 at rebertia.com
Wed Apr 22 18:46:40 EDT 2009


On Wed, Apr 22, 2009 at 3:32 PM, Benjamin Peterson <benjamin at python.org> wrote:
> Chris Rebert <clp2 <at> rebertia.com> writes:
>> Common wart to run into as of late. fn (in the lambda) doesn't get
>> evaluated until the call-time of the lambda, by which point the loop
>> has finished and the loop variable has been changed to its final
>> value, which is used by the lambda.
>
> How is that a wart?

A lot of people are being bitten by it, judging by the number of
threads I've seen about problems/surprises like the OP's. In fact,
there was a thread (or 2?) a while ago about adding some sort of
language feature to work around it (might have been on -ideas).

"Pitfall" or "gotcha" would have been a more accurate phrasing. I only
mean that it's caused a nontrivial number of inobvious (to those not
in the know) bugs.

Cheers,
Chris
-- 
I have a blog:
http://blog.rebertia.com



More information about the Python-list mailing list