Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error - __init__() takes exactly 2 arguments (1 given)

Tags:

python

I'm trying to initialize the class (extraropt) from another .py but it gives me an error, I've searched but I haven't found a solution.

Heres the code of the one py I'm calling from:

main.py:

class GameWindow(ui.ScriptWindow):
    def __init__(self, stream):
        import extraop

        exec 'extraop.extraropt().Show(stream)'

And here's the code of the one py I'm trying to call(init and del only):

extraop.py

class extraropt(ui.Window):
    def __init__(self, stream):
        ui.Window.__init__(self)
        self.BuildWindow()
        self.stream=stream
    def __del__(self):
        ui.Window.__del__(self)

It gives this error:

Error - __init__() takes exactly 2 arguments (1 given)
like image 998
Miguel Silva Avatar asked Feb 06 '26 20:02

Miguel Silva


1 Answers

In the line

exec 'extraop.extraropt().Show(stream)'

You are implicitly calling extraropt.__init__() by creating a new instance of extraopt. In your code, you show that extraropt.__init__() takes a second (stream) argument, so you have to pass that in.

extraop.extraropt(stream).Show()

Incidentally, there is no reason why you should be doing an exec rather than explicitly calling it as I did above. There is also no reason for you to have a __del__() method defined as you only call the parent __del__() method anyway.

like image 147
Joel Cornett Avatar answered Feb 09 '26 11:02

Joel Cornett