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

后端 未结 4 2011
暗喜
暗喜 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:19

    you can also avoid writing a concrete class name in older versions of python by using

    def __init__(self):
        super(self.__class__, self)
        ...
    

提交回复
热议问题