任何人都可以用适当的例子向我解释是否存在差异
>>> import inspect
>>> inspect.getmembers(1)
Run Code Online (Sandbox Code Playgroud)
和
>>> type(1).__dict__.items()
Run Code Online (Sandbox Code Playgroud)
和
>>> dir(1)
Run Code Online (Sandbox Code Playgroud)
除了它们按顺序显示减少数量的属性和方法.1是整数(但它可以是任何类型.)
编辑
>>>obj.__class__.__name__ #gives the class name of object
>>>dir(obj) #gives attributes & methods
>>>dir() #gives current scope/namespace
>>>obj.__dict__ #gives attributes
Run Code Online (Sandbox Code Playgroud)