class variable won't icrement!
Steve Holden
sholden at holdenweb.com
Thu Sep 12 11:57:00 EDT 2002
"Aahz" <aahz at pythoncraft.com> wrote in message
news:alq9hf$bn$1 at panix1.panix.com...
> In article <alpner$bm$1 at wanadoo.fr>,
> Eric Brunel <eric.brunel at pragmadev.com> 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 namespace.
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
like
self.var += 1
can be so confusing. Especially when you compare operations that give
different results for mutable and immutable objects.
regards
-----------------------------------------------------------------------
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/
Previous .sig file retired to www.homeforoldsigs.com
-----------------------------------------------------------------------
More information about the Python-list
mailing list