Weird lambda behavior

Chris Rebert clp2 at
Thu Apr 23 00:46:40 CEST 2009

On Wed, Apr 22, 2009 at 3:32 PM, Benjamin Peterson <benjamin at> wrote:
> Chris Rebert <clp2 <at>> 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.

I have a blog:

More information about the Python-list mailing list