Python获取当前类的所有成员属性
1 # -*- coding: utf-8 -*- 2 class Market(object): 3 def __init__(self): 4 self.title = 'apple' 5 self.count = '20' 6 def list_all_member(self): 7 for name,value in vars(self).items(): 8 print('%s=%s'%(name,value)) 9 if __name__== '__main__': 10 market= Market() 11 market.list_all_member()
输出结果如下:
1 count = 20 2 titlte = apple