You're defining instance variables, not class variables. To get instance variables, you'll have to instantiate it:
>>> f = Foo(1, 2, 3)
>>> dir(f)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'test1', 'test2', 'test3']
There, you have all the attributes.
But if you only want the attributes you declared, use f.__dict__
:
>>> f.__dict__
{'test3': 3, 'test2': 2, 'test1': 1}
Or alternatively, use vars(f)
.
But if you wanted to get the class variables, just refer to the class itself:
>>> class Foo:
abcd = 10
def __init__(self, test1, test2, test3):
self.test1=test1
self.test2=test2
self.test3=test3
>>> vars(Foo)
mappingproxy({'abcd': 10, '__dict__': <attribute '__dict__' of 'Foo' objects>, '__doc__': None, '__module__': '__main__', '__init__': <function Foo.__init__ at 0x00000000032290D0>, '__weakref__': <attribute '__weakref__' of 'Foo' objects>})
>>> dir(Foo)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'abcd']
Hope this helps!