loop scope

Jacek Generowicz jacek.generowicz at cern.ch
Wed Mar 17 17:05:15 EST 2004


mwilson at the-wire.com (Mel Wilson) writes:

>    Far too few.  After the `nested x` statement comes
> `nested nested x` and `nested nested nested x`,

Nope. You would never write more than one "nested". It would be an
instruction to Python _not_ to treat the name as local, just because
there is an assignment to the name in the local scope. The nearest
scope that has a binding for the name shadows all others ... just like
nested scopes work today. The only problem (today) is that an
assignment to the name creates a binding in the local scope, so there
is no way of _re_-binding a name in an enclosing scope.

Languages which support nested scopes have been around for decades,
and none of them have (to my knowledge) found the need for specifying
which nested scope you want to look in; the nearest one is the one you
want. That's, partly, the point of nested scopes.



More information about the Python-list mailing list