python vars()
Python vars() function returns __dict__ attribute for a module, class, instance, or any other object with a __dict__ attribute. So the output of vars() function is a dictionary.
Python vars()函数为模块,类,实例或具有__dict__属性的任何其他对象返回__dict__属性。 因此,vars()函数的输出是一个dictionary 。
Python vars() (Python vars())
Python vars() function syntax is:
Python vars()函数语法为:
vars([object])
- If no argument is provided, vars() act like locals() function. 如果未提供任何参数,则vars()的作用类似于locals()函数。
- The arguments can be module, class or instance of a class. 参数可以是模块,类或类的实例。
- If the specified argument doesn’t have __dict__ attribute, the
TypeError
exception is thrown with messageTypeError: vars() argument must have __dict__ attribute
. 如果指定的参数不具有__dict__属性,则会引发TypeError
异常并显示消息TypeError: vars() argument must have __dict__ attribute