check the documentation for the dir
method, which has the following description:
If the object supplies a method named _ dir__, it will be used; otherwise
the default dir () logic is used and returns
that is, as long as the object itself has a _ _ dir__
method, the two should actually be the same. But try the following example and find that the two are not consistent:
class A(object):
pass
print(dir(A))
print(A.__dir__(A))
The _ _ dir__
method has some extra properties, such as _ _ mro__
, _ _ name__
, and so on. Why?