[Python-Dev] PEP for Better Control of Nested Lexical Scopes
James Y Knight
foom at fuhm.net
Fri Feb 24 16:40:57 CET 2006
More information about the Python-Dev mailing list
Fri Feb 24 16:40:57 CET 2006
- Previous message: [Python-Dev] PEP for Better Control of Nested Lexical Scopes
- Next message: [Python-Dev] PEP for Better Control of Nested Lexical Scopes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Feb 24, 2006, at 1:54 AM, Greg Ewing wrote: > Thomas Wouters wrote: >> On Thu, Feb 23, 2006 at 05:25:30PM +1300, Greg Ewing wrote: >> >>> As an aside, is there any chance that this could be >>> changed in 3.0? I.e. have the for-loop create a new >>> binding for the loop variable on each iteration. >> >> You can't do that without introducing a whole new scope >> for the body of the 'for' loop, > > There's no need for that. The new scope need only > include the loop variable -- everything else could > still refer to the function's main scope. No, that would be insane. You get the exact same problem, now even more confusing: l=[] for x in range(10): y = x l.append(lambda: (x, y)) print l[0]() With your suggestion, that would print (0, 9). Unless python grows a distinction between creating a binding and assigning to one as most other languages have, this problem is here to stay. James
- Previous message: [Python-Dev] PEP for Better Control of Nested Lexical Scopes
- Next message: [Python-Dev] PEP for Better Control of Nested Lexical Scopes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list