class variable won't icrement!

Aahz aahz at
Thu Sep 12 12:20:11 EDT 2002

In article <PQ2g9.191834$l_4.58187 at>,
Steve Holden <sholden at> wrote:
>"Aahz" <aahz at> wrote in message
>news:alq9hf$bn$1 at
>> In article <alpner$bm$1 at>,
>> Eric Brunel  <eric.brunel at> wrote:
>>>I always found that inheritance of class attributes to instance attributes
>>>was really misleading, and I even think it would be better if it were
>>>simply removed from Python. IMHO, it would far more conform to the
>>>"explicit is better than implicit" rule that is one of the basis of Python.
>> If I think of it as "scope resolution" rather than "inheritance", I find
>> that it makes more sense.  It works exactly the same way as hiding a
>> global with a local.
>Well, not quite exactly the same way. If a local hides a global
>then there's no way to access the global without explicit use of a

Exactly!  The only difference is that it's an error in a function to
attempt to read a global and then later modify it (in the absence of the
global statement).

>A class variable is available by instance-qualified name up until the time
>the instance variable with the same name is created, which is why statements
>    self.var += 1
>can be so confusing. Especially when you compare operations that give
>different results for mutable and immutable objects.

It might make sense to tighten the rules for modifying class variables,
just the way this gives an error:

x = 1
def foo():
    print x
    x = x + 1

The mutable/immutable thing is exactly the same for functions and
Aahz (aahz at           <*>

Project Vote Smart:

More information about the Python-list mailing list