- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在关于 Custom Classes 的部分的 The Python Language Reference据称:
Special attributes:
__name__
is the class name;__module__
is the module name in which the class was defined;__dict__
is the dictionary containing the class’s namespace;__bases__
is a tuple (possibly empty or a singleton) containing the base classes, in the order of their occurrence in the base class list;__doc__
is the class’s documentation string, orNone
if undefined.
那么,自定义类的 __bases__
可以“可能为空”吗?如果在 Python 3
中所有内容都隐式继承自 object
,那如何实现?
唯一具有空 __bases__
的类是 object
本身:
>>> object.__bases__
()
我错过了什么吗?
最佳答案
这条线在 Python 3 发布之前就已经存在了。这是 2007 commit .当对象模型被修改以摆脱旧式类时,看起来文档中的信息没有通过审查,现在可能只是错误信息。
我可以建议你提出一个 documentation issue清除它是否不正确/过时。
关于python - 具有空 __bases__ 属性的自定义类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40697047/
是否可以使用 get-set 属性覆盖元类(即派生自 type 的类)的 __bases__ 字段?以下代码适用于获取 C.__bases__,但不适用于设置: class Meta(type):
在关于 Custom Classes 的部分的 The Python Language Reference据称: Special attributes: __name__ is the class n
类对象有一个 __bases__ (和一个 __base__ )属性: >>> class Foo(object): ... pass ... >>> Foo.__bases__ (,) 遗憾
以下代码在 Python 3.x 中不起作用,但它曾经用于旧式类: class Extender: def extension(self): print("Some work.
也许这是一个微不足道的问题。在 python 下,为什么 self.__class__.__bases__ 没有回溯到 object?我的只显示了类(class)之上的单亲 parent 的元组。 最
我找到了以下函数,但我不知道为什么需要额外的 __bases__ 扫描: def getMembersWithBases(classType): members = set(dir(class
我在 Python 的 REPL 中试过这个: >>> class Foo: ... def f():{} ... >>> >>> type(Foo) >>> Foo.__bases__ () >
我是一名优秀的程序员,十分优秀!