TypeError: __init__() takes 1 positional argument but 2 were given

Stephen Waterbury waterbug at pangalactic.us
Thu Apr 29 17:03:27 BST 2021


Yes, that error message is confusing if you haven't seen it before --
in python, any bound method implicitly/automagically gets the "self"
argument, so calling it without arguments already gives it one
argument, "self".  In your code, you explicitly added "self", so that
is considered a second argument.  So if the __init__ method for SitesWindow
has a signature like:  def __init__(self): ...
then you can just create a SitesWindow using"SitesWindow()".

Steve

On 4/29/21 11:33 AM, Rich Shepard wrote:

> I'm trying to add a tab's content to a QTabWidget but get this error:
> $ python mwe.py Traceback (most recent call last):
>   File "mwe.py", line 31, in <module>
>     mw = MainWindow()
>   File "mwe.py", line 20, in __init__
>     self.sw = SitesWindow(self)
> TypeError: __init__() takes 1 positional argument but 2 were given
>
> It's been a long time since I did any serious python coding and 
> despite my
> researching this error on the Web I still fail to see the solution. I 
> know
> it's simple but I don't see the two arguments to the assignment. An 
> minimal
> example is attached.
>
> Please point out my error.
>
> TIA,
>
> Rich
>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210429/47ae9234/attachment.htm>


More information about the PyQt mailing list