如果 __init__ 只调用 super.__init__ 是否有必要?

Yep*_*_Me 5 python oop inheritance python-multithreading python-2.7

我正在对类进行子threading.Thread类化,它目前看起来像这样:

class MyThread(threading.Thread):
    def __init__(self:
        super(MyThread, self).__init__()

    def run(self):
        # Do some stuff
Run Code Online (Sandbox Code Playgroud)

__init__在这种情况下是必需的吗?如果我省略它,它会自动调用吗?

小智 7

不,在这种情况下不需要它。

实例化一个类时,如果没有__init__方法,__init__则自动调用超类的方法。