[英]Is __init__ necessary if it only calls super.__init__?
I'm subclassing the threading.Thread
class and it currently looks like this: 我是
threading.Thread
类的子类,它目前看起来像这样:
class MyThread(threading.Thread):
def __init__(self:
super(MyThread, self).__init__()
def run(self):
# Do some stuff
Is the __init__
required in this instance? 这个例子中是否需要
__init__
? If I leave it out, is it called automatically? 如果我把它留下来,是自动调用吗?
No, it is not needed in this case. 不,在这种情况下不需要。
When instantiating a class, if it has no __init__
method, the __init__
method of the super class is automatically called. 实例化类时,如果没有
__init__
方法,则会自动调用超类的__init__
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.