1

From

a = []

class A(object):
    def __init__(self):
        self.myinstatt1 = 'one'
        self.myinstatt2 = 'two'

to

a =['one','two']
avasal
  • 14,350
  • 4
  • 31
  • 47
  • 2
    possible duplicate of [How to enumerate an object's properties in Python?](http://stackoverflow.com/questions/1251692/how-to-enumerate-an-objects-properties-in-python) – NullUserException Nov 21 '12 at 04:19

2 Answers2

9

Python has a handy builtin called vars that will give the attributes to you as a dict:

>>> a = A()
>>> vars(a)
{'myinstatt2': 'two', 'myinstatt1': 'one'}

To get just the attribute values, use the appropriate dict method:

>>> vars(a).values()
['two', 'one']

In python 3, this will give you a slightly different thing to a list - but you can just use list(vars(a).values()) there.

lvc
  • 34,233
  • 10
  • 73
  • 98
2

Try to look into the __dict__ attribute. It will help you:

a = A().__dict__.values()
print a
>>> ['one', 'two']
Artsiom Rudzenka
  • 27,895
  • 4
  • 34
  • 52