class static variables and __dict__

Zack goldsz at gmail.com
Sat Feb 16 19:03:48 EST 2008


Dustan wrote:
> On Feb 16, 4:40 pm, Zack <gol... at gmail.com> wrote:
>> what method can you use on x to find all available
>> attributes for that class?
> 
>>>> class Foo(object):
> 	bar = "hello, world!"
> 	def __init__(self, baz):
> 		self.baz = baz
> 
>>>> x = Foo(42)
> 
>>>> x.__dict__.keys() # Does not include bar
> ['baz']
> 
>>>> dir(x) # Includes bar plus some methods
> ['__class__', '__delattr__', '__dict__', '__doc__',
> '__getattribute__', '__hash__', '__init__', '__module__', '__new__',
> '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
> '__weakref__', 'bar', 'baz']

I knew there was something simple I was forgetting.
Thanks

-- 
Zack



More information about the Python-list mailing list