Class inside Class: Error: Page1.__init__.My_Data.__init__() got an unexpected keyword argument 'Name'


When i try to start my script, i get a error. I have main class Page1 and inside is My_Data class and function1 function. The error is:

TypeError: Page1.__init__.<locals>.My_Data.__init__() got an unexpected keyword argument 'Name'

class Page1(tk.Frame):
    def __init__(self, master, other, **kw):
        super().__init__(master, **kw)


        class My_Data():
            def __init__(self):
                self.Name: str
                self.Year: float

        def function1(self):

            My_Dictionary = {}
            x = cursor.execute("sql")

Asked By: Alcantara



It’s because My_Data class doesn’t have parameters Name and Year in its __init__ function. Just add the two params.

class My_Data():
    def __init__(self, Name, Year):
        self.Name = Name
        self.Year = Year
Answered By: Lahcen YAMOUN
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.