where are the "class variables"?

John Roth newsgroups at jhrothjr.com
Tue Sep 30 22:01:46 CEST 2003

"Dominik Kaspar" <dokaspar at student.ethz.ch> wrote in message
news:62e9c66e.0309301057.65f24a3b at posting.google.com...
> i'm used to java and its strict way of defining variables. so how is
> it possible to reach something like a class variable in python?
> with the following code i didn't have much succes...
> class Server(threading.Thread):
>     running = 0  (??)

This is correct - it binds 0 to the identifier running in the class.

>     def run(self):
>         running = 1

use Server.running

>         while running:

use while Server.running:
>             print "do something here..."
>     def exit(self):
>         running = 0

use Server.running

> thanks
> -- dominik

If you want to put an identifier in the class, reference the
class directly, or inherit from object and use a class method.

John Roth

More information about the Python-list mailing list