如何部分重写(附加)方法?

时间:2018-09-09 07:48:49

标签: python python-3.x class override

被覆盖的方法完全替换了父类的方法:

class Msg:

    def proc(self):
        # this part is common to all methods
        print("common part")
        # I would like the override to start here
        pass

class A(Msg):

    def proc(self):
        # this should be appended below pass above
        print("overridden part")

A().proc()

是否可以通过保留“公共”部分并附加一个特定的部分(每个类)来部分替换该方法?

0 个答案:

没有答案