Nested scopes, and augmented assignment

Piet van Oostrum piet at cs.uu.nl
Fri Jul 7 19:03:12 EDT 2006


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

>AP> On 2006-07-07, Piet van Oostrum <piet at cs.uu.nl> wrote:
>>>>>>>> Antoon Pardon <apardon at forel.vub.ac.be> (AP) wrote:
>>> 
>AP> Could you maybe clarify what problem we are discussing? All I wrote
>AP> was that with an assignment the search for the lefthand variable
>AP> depends on whether the lefthand side is a simple variable or
>AP> more complicated. 
>>> 
>>> What do you mean with `the lefthand variable'? Especially when talking
>>> about `complicated lefthand sides'?

>AP> The name on the left side of an assignment that refers to a variable,
>AP> as opposed to names that are attributes.

So let me get it clear:
In a.b = c, a is the lefthand variable, but b is not?

If that is what you mean then I interpret your statement 
>AP> `with an assignment the search for the lefthand variable
>AP> depends on whether the lefthand side is a simple variable or
>AP> more complicated'

as meaning that the search for `a' in `a.b = c' would be different than the
search for `a' in `a = b'. 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.
 
-- 
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