python - 如何在Python中使用 'super(type)'?AttributeError : 'super' object has no attribute 'test'

标签 python

这是我的代码:

class A(object):
   def test(self): pass
class B(A): pass

我的问题是当我运行 super(B).test 时,出现以下异常:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'super' object has no attribute 'test'

我看到 python 文档:“super(type) -> unbound super object”,为什么它不起作用?我希望有人能给出一个正确使用“super(type)”的例子,谢谢

最佳答案

如果要调用test,这里不需要用super。

b = B()
b.test()

关键词super在python中通常用在内部类中。 感谢@PM 2Ring 的提示。

关于python - 如何在Python中使用 'super(type)'?AttributeError : 'super' object has no attribute 'test' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44493780/

相关文章:

Python - 从管道中简单读取行

python - Pandas groupby 查找两个日期时间列之间的差异

python - 使用 BeautifulSoup 索引错误进行网页抓取

python - 应用程序用户记录的地理位置 - 哪个位置最重要?

python - Python 如何访问 X11 剪贴板?

python - Python 中十六进制数的二进制补码

python - 类型映射资源以及将列表转换为 vector (以及反之)

python - 将 numpy 数组作为文件存储和加载

python - sqlalchemy中的子查询顺序

python - 将 numpy 数组转换为共享内存数组的代码出现 Pickle 错误