469,271 Members | 1,014 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

static variables?

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
Jul 18 '05 #1
1 1397

<ni**********@cimex.com.cu> wrote in message
news:ma************************************@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

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by James | last post: by
2 posts views Thread by katekukku | last post: by
9 posts views Thread by Bryan Parkoff | last post: by
8 posts views Thread by Simone Chiaretta | last post: by
16 posts views Thread by RB | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.