object.__dict__
和其他地方的隐藏方法设置为这样的:
<dictproxy {'__add__': <slot wrapper '__add__' of 'instance' objects>,
'__and__': <slot wrapper '__and__' of 'instance' objects>,
'__call__': <slot wrapper '__call__' of 'instance' objects>,
'__cmp__': <slot wrapper '__cmp__' of 'instance' objects>,
'__coerce__': <slot wrapper '__coerce__' of 'instance' objects>,
'__contains__': <slot wrapper '__contains__' of 'instance' objects>,
'__delattr__': <slot wrapper '__delattr__' of 'instance' objects>,
'__delitem__': <slot wrapper '__delitem__' of 'instance' objects>,
'__delslice__': <slot wrapper '__delslice__' of 'instance' objects>,
'__div__': <slot wrapper '__div__' of 'instance' objects>,
'__divmod__': <slot wrapper '__divmod__' of 'instance' objects>,
...
这些是什么以及它们的用途是什么?
编辑:
这是以下的输出:
class A:
pass
b = A()
print(type(b).__dict__)
根据https://doc.sagemath.org/html/en/reference/cpython/sage/cpython/wrapperdescr.html https://doc.sagemath.org/html/en/reference/cpython/sage/cpython/wrapperdescr.html :
插槽包装器安装在扩展类型的字典中,以访问用 C 实现的特殊方法。例如,object.__init__ 或 Integer.__lt__。请注意,槽包装器始终是未绑定的(有一个称为方法包装器的绑定变体)。
因此,它们实际上是包装 C 实现的对象方法的方法。 Python 中的许多神奇方法和属性都是通过 C 对象上的槽包装器实现的。由于 Python 的大多数实现都是用 C 编写的,所以这是有道理的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)