class static variables and __dict__

Diez B. Roggisch deets at nospam.web.de
Sun Feb 17 00:04:58 CET 2008


Zack schrieb:
> If I have a class static variable it doesn't show up in the __dict__ of 
> an instance of that class.
> 
> class C:
>    n = 4
> 
> x = C()
> print C.__dict__
> {'__module__': '__main__', '__doc__': None, 'n': 4}
> print x.__dict__
> {}
> 
> This behavior makes sense to me as n is not encapsulated in x's 
> namespace but what method can you use on x to find all available 
> attributes for that class?

x.__class__.__dict__

Diez




More information about the Python-list mailing list