【问题标题】:How To Call An Overridden Method Outside The Classes如何在类之外调用重写的方法
【发布时间】:2021-06-11 01:18:31
【问题描述】:
class class1 :

    def method1(self):
        print("Method1 in Class1")


class class2(class1) :

    def method1(self):
        class1.method1(self)
        print("Method1 in Class2")

ob = class2()

ob.method1()

这是我的问题... 我想在class2 之外致电class1 中的method1。 同样,是否有在ob.method1() 内调用的方法 没有在class2method1 中调用它?

【问题讨论】:

  • this 是您要找的吗?

标签: python class object methods


【解决方案1】:

你可以这样做,但这是一个非常糟糕的主意。您的操作方式与您在 class2 中的操作方式完全相同:

class1.method1(ob)

【讨论】:

    猜你喜欢
    • 2011-12-26
    • 2017-05-05
    • 2017-01-18
    • 2021-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多