获取Python中类中所有变量的值

时间:2016-10-21 12:21:14

标签: python

假设我有一个包含100个变量的类,每个变量都有值。如何在不知道变量名称的情况下获取每个值。例如:

class Stuff():
    a = 1
    b = 2
    c = 3
    d = 9.36
    e = "f"
    #and so on...

for i in dir(Stuff):
    print(Stuff.i)    #Does not work but it's what I want to achieve

0 个答案:

没有答案