Class Variable Access and Assignment

Antoon Pardon apardon at forel.vub.ac.be
Thu Nov 3 08:35:35 EST 2005


Op 2005-11-03, venk schreef <venkatasubramanian at gmail.com>:
> You see,
>      The seen behavior is due to the result of python's name
> binding,scoping scheme.

I know what causes the behaviour. But I still think it is
not sane behaviour.


> ...
>
> the same thing happens in the case of b.a = b.a + 2 .... search for b.a
> not found, read the value from the enclosing scope (of the class
> object).... then assign b.a to the local scope, with the value 3.

This is an explanation depending on a specific implementation.

Now can you give me a language design argument that supports the 
idea that in "b.a = b.a + 2" b.a refers to two different objects.

And even if you could do that, can you give such an argument that
in "b.a += 2" that one occurence of b.a should refer to two different
objects.

Suppose I have code like this:

  for i in xrange(1,11):
    b.a = b.a + i

Now the b.a on the right hand side refers to A.a the first time through
the loop but not the next times. I don't think it is sane that which
object is refered to depends on how many times you already went through
the loop.

-- 
Antoon Pardon



More information about the Python-list mailing list