where are the "class variables"?
Jeff Epler
jepler at unpythonic.net
Tue Sep 30 16:39:20 EDT 2003
On Tue, Sep 30, 2003 at 01:27:15PM -0700, Dominik Kaspar wrote:
> maybe my question was badly formulated. i give it a new try:
> why does the following program give the output "0 0" and not "1 0"?
> why does it loop forever? and how could that problem be fixed?
Because inside functions, an assignment to a simple name, like
running = 1
refers to a local variable, unless there is a "global" statement in
which case it refers to a module-level variable:
global running
running = 1
(this is still not what you want)
You want to refer to Server.running, as suggested in another message:
def run(self):
Server.running = 1
jeff
PS The first server.running might print 0 if the first line of
Server.run hasn't executed the first statement yet, of course, but
that's another story
More information about the Python-list
mailing list