Python is wierd!

Vespe Savikko vespe at cs.tut.fi
Thu Jul 27 06:39:58 EDT 2000


Also sprach "Rainer Deyke" <root at rainerdeyke.com>:

  Static variables and methods are a mess anyway.  In Python, there is
  no need for them - just place the variables and functions outside
  the class.  In Java, they are a (poor) substitite for placing things
  outside the class.  In C++, static class members are sometimes
  useful for access control and templates, both of which have no place
  in Python.
  
I think you are being too hard on static variables. The class
attributes have their uses in Python as well. For example, since class
attribute becomes a part of the class.__dict__, you can later define
that same attribute in the subclasses as well, and still can retain
the access to the 'same' class attribute in the superclass. In other
words the value of the class attribute can be seen to as accumulating
knowledge: besides its own class attribute a subclass instance can
query the value of the class attribute of the base class as well.

I am using the above mentioned mechanism in the current system I am
building and that experience have made me a strong believer in the
object-oriented features of Python. Especially the access control by
convention (name mangling) and different special attributes
(__class__, __name__, __bases__, ...)  gives programmer a very
powerful set of tools to work with. One can traverse easily upwards
the class hierarchy and examine the features of the base classes.
  
  ++Vespe
  
-- 
  ------------------------------------------------------------------
       Vespe Savikko     vespe at cs.tut.fi     - to doom de doomsday -



More information about the Python-list mailing list