如何在 python 中重命名超类的方法?

How do I rename a superclass's method in python?

我有一个包含方法 run() 的超类。

我创建了超类的子类,我希望它有自己的 run() 方法。但是,我想在这个新对象上的名为 oldrun() 的方法中保留旧 运行 方法的功能。

我将如何在 Python 中执行此操作?

你可以这样做:

class Base(object):
    def run(self):
        print("Base is running")

class Derived(Base):
    def run(self):
        print("Derived is running")

    def oldrun(self):
        super().run()