python如何从覆盖基类的派生类调用基类中定义的方法?
使用内置的 super()
函数:
class Derived(Base):
def meth(self):
super(Derived, self).meth()
对于 Python 3.0之前的版本,您可能正在使用经典类:对于诸如 class Derived(Base): ...
之类的类定义,可以将在 Base
(或 Base
中的一个的基类)中定义的方法 meth()
调用为 Base.meth(self, arguments...)
。这里, Base.meth
是一个未绑定的方法,因此您需要提供 self
参数。
来源:PY学习网:原文地址:https://www.py.cn/article.html