如果只调用super .__ init__,__ init是否必要?

时间:2014-10-29 05:07:09

标签: python oop python-2.7 inheritance python-multithreading

我是threading.Thread类的子类,目前看起来像这样:

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

    def run(self):
        # Do some stuff

此实例中是否需要__init__?如果我把它留下来,是自动调用吗?

1 个答案:

答案 0 :(得分:4)

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

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