[Python-3000] end scope of iteration variables after loop

Nicholas T gatoatigrado at gmail.com
Thu Apr 17 03:25:26 CEST 2008


previous discussion at
http://mail.python.org/pipermail/python-dev/2005-September/056677.html

I don't agree with the author that
>>> i = 3
>>> for i in range(11): pass
...
>>> i
10
is much less confusing than i returning 3. furthermore, his C example makes
it obvious that "i" will be available in the scope after the loop. There's
no way to know now, but I think mistakes would be less frequent.

Additionally, what are others' opinions about this "pseudo-namespace" (i.e.
scoping) being slow? Admittedly, I don't know much about the current
parser's implementation, but it doesn't seem like scoping necessitates slow
parsing -- considering it's done in other languages, and python functions
have reasonable scope.

>>> def do_nothing(i): i = 3
...
>>> do_nothing(1)
>>> i
10

Nicholas

On Wed, Apr 16, 2008 at 5:52 PM, Nicholas T <ntung at ntung.com> wrote:

> hello all,
>
>    A few times in practice I have been tripped up by how Python keeps
> variables in scope after a loop--and it wasn't immediately obvious what the
> problem was. I think it is one of the ugliest and non-intuitive features,
> and hope some others agree that it should be changed in py3k.
>
> >>> for a in range(11): pass
> ...
> >>> print(a)
> 10
>
> Thanks,
> Nicholas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20080416/da598ada/attachment.htm 


More information about the Python-3000 mailing list