Variables common to all objects of a class

Thomas Guettler zopestoller at thomas-guettler.de
Fri Apr 12 08:05:45 EDT 2002


Hi!

How do you store variables which should be common to all
objects of a class?

I would do it like this. Is this the right pyhton-way?

#foo.py
class_variable=0
def class_method():
     print "I work only on class variables"

class foo:
     object_variable=1
     def my_class_variable(self):
         print "cv", class_variable, "ov", self.object_variable


if __name__=="__main__":
     f=foo()
     f.my_class_variable()
     import foo
     foo.class_method()

thomas




More information about the Python-list mailing list