[Zope] Verrryy strange behavior (NameError)
Thomas B. Passin
tpassin@mitretek.org
Fri, 6 Apr 2001 16:37:28 -0400
Just to add to what Randall has said:
When you declare a local variable in Python - that is, a variable that is
declared within a function definition - it "shadows" any other variable of
that name until the function exits. This means that if you assign a value
to a variable of that name, Python creates a new one and uses that within
the function. Many languages operate that way, not just Python.
As Randall said, you can defeat this by using the "global" statement. It
still isn't really "global", though. I believe it applies just within the
same module as the function is defined in.
Cheers,
Tom P
Randall F. Kern wrote -
This is just normal python. When you want to assign to a global
variable inside a function, you have to declare the variable as a
global:
_stateVariable = 0
class
def func()
>>> global _stateVariable
_stateVariable = 1
-Randy