来自
a = []
class A(object):
def __init__(self):
self.myinstatt1 = 'one'
self.myinstatt2 = 'two'
到
a =['one','two']
请您参考如下方法:
Python 有一个名为 vars 的方便的内置函数,它会将属性作为字典提供给您:
>>> a = A()
>>> vars(a)
{'myinstatt2': 'two', 'myinstatt1': 'one'}
要仅获取属性值,请使用适当的 dict 方法:
>>> vars(a).values()
['two', 'one']
在 python 3 中,这会给你一个与列表略有不同的东西 - 但你可以在那里使用 list(vars(a).values())。
