1

I have threading class in serverThread.py file as shown:

import threading

class serverThread(threading.Thread):
    def __init__(self, name):
        try:
            threading.Thread.__init__(self)
            self.name = name
        except:
            exit()

    def run(self):
           print("Hello")

I created a new project.I want to inherit class from above class as shown:

import serverThread


class tcpThread(serverThread):
    def __init__(self, name):
        serverThread.__init__(self,name)

    def run():
        serverThread.run(self)


t1 = tcpThread("Tcp Server")
t1.start()

When I run this script gives me error:

Error: Traceback (most recent call last): File "serverTcpThread.py", line 4, in <module> class tcpThread(serverThread): TypeError: module.__init__() takes at most 2 arguments (3 given)

4
  • I've answered but it seems that the error you're reporting doesn't happen here. The other error is real, though. Commented Jan 17, 2018 at 9:07
  • also: paste the error + traceback as text. Images aren't done for that. Commented Jan 17, 2018 at 9:08
  • from serverThread import serverThread Commented Jan 17, 2018 at 9:08
  • 1
    Possible duplicate of TypeError: module.__init__() takes at most 2 arguments (3 given) Commented Jan 17, 2018 at 9:10

1 Answer 1

2

The error you're reporting is probably because the base class is imported from a bad path, cannot reproduce here.

That said, there's another (similar) error: when redefining the run method, you have to pass the self parameter

class tcpThread(serverThread):
    def __init__(self, name):
        serverThread.__init__(self,name)

    def run(self):
        serverThread.run(self)

the code runs fine after that. note that there's no need to redefine the run method only to call the parent method.

Sign up to request clarification or add additional context in comments.

3 Comments

are you sure you're not importing another version of your mother class? in another file?
Have you tried it on your own computer.Because it is very simple code.If you could run, I should look at my side very carefully
of course I tried. I pasted both objects in the same file and it worked (apart from this self issue)