[Python-ideas] Changing semantics of for-loop variable (was: Tweaking closures ...)

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Sep 29 23:31:51 CEST 2011

Guido has asked me to start a new thread for discussing
this idea.

To recap, instead of trying to come up with some new
sugar to make the default-argument hack taste slightly
less bitter, I suggest making a small change to the
semantics of for-loops:

If the loop variable is referenced from an inner scope,
instead of replacing the contents of its cell, create
a *new* cell on each iteration.

Code following the loop would then continue to see the
last value bound to the loop variable, as now, but
inner functions would capture different versions of


More information about the Python-ideas mailing list