Nested scopes hitch
François Pinard
pinard at iro.umontreal.ca
Mon Apr 8 08:49:13 EDT 2002
[Graham Ashton]
> I remember being slightly surprised by the fact that self finds class
> variables. Is there any particular reason why, considering that the
> you can reference them as ClassName.var anyway?
Hello, Graham. I often found it useful, in a hierarchy of classes, being
able to preset a default value in all objects by using a class variable in
a base class, then overriding this default at __init__ time (or otherwise)
in only a few of the derived classes. This relies on the fact that `self',
everywhere, finds class variables when not overridden.
--
François Pinard http://www.iro.umontreal.ca/~pinard
More information about the Python-list
mailing list