How to define a GLOBAL Variable ?
François Pinard
pinard at iro.umontreal.ca
Thu Aug 2 10:40:16 EDT 2001
[Peter Moscatt]
> If I wish to define a variable that I want to become global to ALL classes
> within a .py file - how is this best achieved ?
Hell, Peter.
It's easy (like most things in Python!). Just define your class global
variable, using the class name to the left of a dot. For example:
>>> class Factory:
... def printer(self):
... print self.value
...
>>> a = Factory()
>>> b = Factory()
>>> Factory.value = 3.1415926
>>> a.printer()
3.1415926
>>> b.printer()
3.1415926
--
François Pinard http://www.iro.umontreal.ca/~pinard
More information about the Python-list
mailing list