A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-February/061788.html below:

[Python-Dev] PEP for Better Control of Nested Lexical Scopes

[Python-Dev] PEP for Better Control of Nested Lexical ScopesJames Y Knight foom at fuhm.net
Fri Feb 24 16:40:57 CET 2006
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
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4