[Zope] Verrryy strange behavior (NameError)
Randall F. Kern
randy@spoke.net
Fri, 6 Apr 2001 13:10:21 -0700
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 =3D 0
class
def func()
>>> global _stateVariable
_stateVariable =3D 1
-Randy
-----Original Message-----
From: Andrew Athan [mailto:aathan-zope-list%REMOVEME@memeplex.com]
Sent: Friday, April 06, 2001 1:01 PM
To: zope@zope.org
Subject: RE: [Zope] Verrryy strange behavior (NameError)
=20
I'm sending this in case my sagga helps some other relative newcomer.
=20
I suspect this problem has something to do with python1.5.2's (or Zope's
hackery of...) handling of namespaces within modules & classes. What I
needed was access to a "static global" variable to store some state for
me. (No, I haven't looked into threads, their existance, or such issues
in Zope). What I was doing was:
=20
_stateVariable=3D0
....
class ....
def fun()
....
_stateVariable=3D1
=20
=20
and this was causing me all kinds of grief. By changing the code to
=20
_stateVariable =3D {'a':0}
...
class ...
def fun()
...
_stateVariable['a']=3D1
=20
everything works just fine. Now, can someone give me the shortcut to
understand WHHHYYY?
=20
A.