相关疑难解决方法(0)

inspect.getmembers()vs __dict __.items()vs dir()

任何人都可以用适当的例子向我解释是否存在差异

>>> 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)

python namespaces

26
推荐指数
1
解决办法
5988
查看次数

标签 统计

namespaces ×1

python ×1