Python vars() 函数的用法
定义和用法
vars() 函数返回对象的 dic 属性。
dict 属性是包含对象的可变属性的字典。
注释:不带参数调用 vars() 函数将返回包含局部符号表的字典。
返回名为 Person 的对象的 dict 属性:
class Person:
name = "Bill"
age = 63
country = "USA"
x = vars(Person)
print(x)
#{'__module__': '__main__', 'name': 'Bill', 'age': 63, 'country': 'USA',
#'__dict__': <attribute '__dict__' of 'Person' objects>, '__weakref__':
#<attribute '__weakref__' of 'Person' objects>, '__doc__': None}