static variables?
John Roth
newsgroups at jhrothjr.com
Fri Mar 19 14:30:13 EST 2004
<niurka.perez at cimex.com.cu> wrote in message
news:mailman.167.1079721766.742.python-list at python.org...
> How can I have a static variable in a python class in a similar fashion as
I
> have them in Java?
> I just want a share the same information in all the instances of a class
and if
> one of the instances changes this information, the rest of them will
notice the
> changes.
> I've been looking for this for a while and I'll appreciate your help
> Niurka
The easiest way is to simply define it in the class, and
then always qualify it by the class when doing an assignment.
class foo:
bar = "xyzzy"
def it(self, new):
foo.bar = new
HTH
John Roth
>
>
More information about the Python-list
mailing list