static attribute

Stephen Hansen news at myNOSPAM.org
Sat May 12 10:53:47 EDT 2001


    The class definition is actually in the scope of its methods. In order
to access it, you must do something like:

    class Name:
        _allNames = {}
        def __init__(self, name):
            self.name = name
            Name._allNames[name] = self

HTH,

--Stephen
(replace 'NOSPAM' with 'seraph' to respond in email)
"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 ?
>
> yours, uwe
>
> --
> Uwe.Schmitt at num.uni-sb.de      Universität des Saarlandes
> phone: +49 (0)681/302-2468     Geb. 36.1, Zi. 4.17, PF 151150
>                                D-66041  Saarbrücken
> http://www.rocksport.de        http://www.rocksport.de/first_ride.mp3
>





More information about the Python-list mailing list