dir() 和 __dict__ 的对比

Posted YingxuanZHANG

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了dir() 和 __dict__ 的对比相关的知识,希望对你有一定的参考价值。

""" dir([object]) -> list of strings

If called without an argument, return the names in the current scope.
Else, return an alphabetized list of names comprising (some of) the attributes
of the given object, and of attributes reachable from it.
If the object supplies a method named __dir__, it will be used; otherwise
the default dir() logic is used and returns:
for a module object: the module‘s attributes.
for a class object: its attributes, and recursively the attributes
of its bases.
for any other object: its attributes, its class‘s attributes, and recursively the attributes of its class‘s base classes. """

以上是关于dir() 和 __dict__ 的对比的主要内容,如果未能解决你的问题,请参考以下文章

python的dir()和__dict__属性的区别

python的dir()和__dict__属性的区别

__doc__,__dict__和__dir__()的区别

python遍历并获取对象属性--dir(),__dict__,getattr,setattr

python中dir(),__dict__

Python __dict__与dir()区别