Nested scopes: why is it weird?
Paul Prescod
paulp at ActiveState.com
Fri Sep 7 15:27:34 EDT 2001
Alex Martelli wrote:
>
>...
>
> Java just doesn't let a local variable 'shadow' one with the
> same name from a lexically-outer scope, and that might have
> been a nice choice too -- just forbid b to have a local variable
> named x if a lexically-outer scope of b had a similarly named
> local variable. Unfortunately, this restriction, which I have
> always liked, and proposed when nested scope were PEP'd, was
> not accepted (though it did get a mention in the PEP), so we'll
> live forevermore with misunderstandings on this point.
Why forevermore? PEP a change to the behaviour and then we can put in a
warning. Python's current behaviour is both confusing and dangerous and
I would love to see someone champion a change. This just shouldn't
silently do the wrong thing:
a = 5
def foo():
a = 6
It would be better to require one of the names to be changed.
--
Take a recipe. Leave a recipe.
Python Cookbook! http://www.ActiveState.com/pythoncookbook
More information about the Python-list
mailing list