本函数是实现返回对象object的属性和属性值的字典对象。如果默认不输入参数,就打印当前调用位置的属性和属性值,相当于locals()的功能。如果有参数输入,就只打印这个参数相应的属性和属性值。
例子:
#vars() print(vars()) class Foo: a = 1 print(vars(Foo)) foo = Foo() print(vars(foo))
结果输出如下:
{‘Foo‘: <class ‘__main__.Foo‘>, ‘B‘: <class ‘__main__.B‘>, ‘__name__‘: ‘__main__‘, ‘__doc__‘: None, ‘__spec__‘: None,...
{‘__module__‘: ‘__main__‘, ‘a‘: 1, ‘__dict__‘: <attribute ‘__dict__‘ of ‘Foo‘ objects>, ‘__weakref__‘: <attribute ‘__weakref__‘ of ‘Foo‘ objects>, ‘__doc__‘: None}
{}
蔡军生 QQ:9073204 深圳
原文地址:http://blog.csdn.net/caimouse/article/details/46489079