[Python-ideas] For loop binding (was Re: Tweaking closures ...)

Masklinn masklinn at masklinn.net
Thu Sep 29 13:16:09 CEST 2011

On 2011-09-29, at 12:52 , Greg Ewing wrote:
> Terry Reedy wrote:
>> No, for loops *do* rebind loop variables each time around.
> I probably should have avoided the word "bind", because it
> can be ambiguous. What I mean is that it assigns a different
> value to the same variable instead of creating a new
> variable. This is different from what equivalent constructs
> in some other languages do.
That's because most (not all, Javascript is a significant
breaker of those rules) C-type languages create a new scope
every time instead of being solely function-scoped no? So
the construct closes over a new name in a different lexical
scope instead of (as in Python, or Javascript) the same name
in the same lexical.

It's not about rebinding so much as about the breadth of
lexical scopes.

More information about the Python-ideas mailing list