class static variables and __dict__

Dustan DustanGroups at gmail.com
Sat Feb 16 18:52:43 EST 2008


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']



More information about the Python-list mailing list