查看dir方法的文档,里面有这样的描述:
If the object supplies a method named __dir__, it will be used; otherwise
the default dir() logic is used and returns
也就是说,只要对象本身有__dir__方法,那么实际上两者应该是一致的。但是尝试下面这个例子,发现两者并不是一致的:
class A(object): pass print(dir(A)) print(A.__dir__(A))
__dir__方法会多出一些属性,例如__mro__, __name__等等,这是为什么呢?
慕桂英3389331
蛊毒传说
随时随地看视频慕课网APP
相关分类