Yep_It's_Me
Yep_It's_Me

Reputation: 4801

Is __init__ necessary if it only calls super.__init__?

I'm subclassing the threading.Thread class and it currently looks like this:

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

    def run(self):
        # Do some stuff

Is the __init__ required in this instance? If I leave it out, is it called automatically?

Upvotes: 6

Views: 399

Answers (1)

user764357
user764357

Reputation:

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.

Upvotes: 8

Related Questions