From
a = []
class A(object):
def __init__(self):
self.myinstatt1 = 'one'
self.myinstatt2 = 'two'
to
a =['one','two']
From
a = []
class A(object):
def __init__(self):
self.myinstatt1 = 'one'
self.myinstatt2 = 'two'
to
a =['one','two']
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.
Try to look into the __dict__
attribute. It will help you:
a = A().__dict__.values()
print a
>>> ['one', 'two']