where are the "class variables"?
Bruno Desthuilliers
bdesth.nospam at removeme.free.fr
Tue Sep 30 18:10:02 EDT 2003
Gerrit Holl wrote:
> 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
>
>
> This is where self is for: self.running refers to the class
> variable 'running'.
Gerrit, I'm afraid you answsered too fast. here, 'self.running' will
refer to (and eventually create) an *instance* variable 'running'. If
the OP want a *class* variable, he needs 'Server.running'.
(Now does the OP really want a class variable or did he meant an
instance variable is another question...)
Bruno
More information about the Python-list
mailing list