static attribute
Alex Martelli
aleaxit at yahoo.com
Sat May 12 11:37:49 EDT 2001
"Uwe Schmitt" <schmitt at num.uni-sb.de> wrote in message
news:9djgnt$570uu$1 at hades.rz.uni-sb.de...
> hi,
>
> i tried to use a static attribute _allNames as follows:
>
>
> class Name:
>
> _allNames={}
>
> def __init__(self,name):
> self.name=name
> _allNames[name]=self
>
>
> X=Name("Xclass")
>
> but i get NameError.... whats wrong ?
You need to set
self._allNames[name] = self
or equivalently
Name._allNames[name] = self
An unqualified identifier only ever refers to a local or global
variable, *NEVER* to the field of an object or class.
Alex
More information about the Python-list
mailing list