Why do I have to specify my own class when using super(), and is there a way to get around it?

后端 未结 4 2081
暗喜
暗喜 2020-12-31 05:45

When using Python\'s super() to do method chaining, you have to explicitly specify your own class, for example:

class MyDecorator(Decorator):
           


        
4条回答
  •  误落风尘
    2020-12-31 06:06

    In Python 3.0, you can use super() which is equivalent to super(ThisClass, self).

    Documentation here. Code sample from the documentation:

    class C(B):
        def method(self, arg):
            super().method(arg)    
            # This does the same thing as: super(C, self).method(arg)
    

提交回复
热议问题