where are the "class variables"?

Tim Rowe tim at remove_if_not_spam.digitig.co.uk
Tue Sep 30 22:21:26 CEST 2003


On 30 Sep 2003 11:57:17 -0700, dokaspar at student.ethz.ch (Dominik
Kaspar) wrote:

>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  (??)
>        
>    def run(self):
>        running = 1
>        while running:
>            print "do something here..."
>
>    def exit(self):
>        running = 0
>
>thanks
>-- dominik

Try:

class Server(threading.Thread):
	running = 0
	def run(self):
		Server.running = 1
		while Server.running:
			print "Hello!"
			self.exit()
	def exit(self):
		Server.running = 0

If you want class /functions/, though, you need a recent version of
Python.




More information about the Python-list mailing list