Nested scopes, and augmented assignment

Piet van Oostrum piet at cs.uu.nl
Sun Jul 9 09:28:42 EDT 2006


>>>>> Antoon Pardon <apardon at forel.vub.ac.be> (AP) wrote:

>AP> It is conceptually different. In the line 'a = b' you don't need to
>AP> search for the scope of a. You know it is the current scope, if you

Except when it has been declared global.

>AP> want to know the scope of b on the other hand, you need to search
>AP> for statement where it is assigned to.

>AP> Sure you can set things up in the interpreter so that the same search
>AP> routine is used, but that is IMO an implementation detail.

>>> Well, it is not. But I can understand the
>>> confusion. Namely, `a = b' introduces a binding for `a' in the local scope,
>>> unless `a' was declared global. So the search will find `a' in the local
>>> scope and it stops there. On the other hand `a.b = c' will not introduce a
>>> binding for `a'. So the search for `a' may stop in the local space (if
>>> there was another binding for `a' in the local scope) or it may need to
>>> continue to outer scopes. The difference, however is not the
>>> complicatedness of the lefthand side but whether the local scope contains a
>>> binding for the variable.

>AP> The complicatedness of the lefthand side, decided on whether the
>AP> variable was introduced in the local scope or not during startup
>AP> time. So that complicatedness decided whether the search was
>AP> to stop at the local level or not.

No, it doesn't. There could be another binding in the same scope. The
complicatedness of this particular assignment doesn't decide anything about
how to search for 'a', but rather the presence or absence of a binding
anywhere in the scope.
-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org



More information about the Python-list mailing list