There are two classes that are inherited by the third. Does not see init of the second class

class Sellary(object): """Sellary Class """ def __init__(self, value): self.value = value def get_sellary(self): return "{}$".format(self.value) class User(object): """ USER CLASS """ def __init__(self, name, sername): self.name = name self.sername = sername def __repr__(self): return "This is {} {}".format(self.name, self.sername) class Developer(User, Sellary): """ THis is a Developer Class who extends User, Sellary""" def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def __repr__(self): return "hello I'm a Developer {} {}".format(self.name, self.sername, self.get_sellary()) if __name__ == '__main__': John = Developer('John', 'Doe', value=10000) print(John) 

The last value argument is not assigned, tell TypeError: __init__() got an unexpected keyword argument 'value' how to use it) TypeError: __init__() got an unexpected keyword argument 'value'

    2 answers 2

    There is a syntax error in the @AndrioSkur response. It is really necessary to call initializers explicitly, but the call will look like this.

     class Developer(User, Sellary): def __init__(self, name, sername, value): Sellary.__init__(self, value) User.__init__(self, name, sername) 

      init is recognized by default through the MRO (that is, from the left class). If you need 2 init calls them explicitly.

       __init__(self, name, surname, value): super(User, self).__init__(name, surname) super(Sellary, self).__init__(value) 

      Although generally speaking, I am not sure about the correctness of this approach ...

      • If you already know the names of ancestor classes, there is no need to define them with super. Prefer explicitly calling User .__ init __ (self, name, surname) - Lecron
      • Have you tried running it? You have no errors? - Axenow
      • TypeError: __init__() takes 2 positional arguments but 3 were given - Philip Pilipchuk
      • ru.stackoverflow.com/posts/890392/revisions in the last revision there is exactly the same calling code super. And I don’t know exactly mb the author made a mistake with the version of python in the label, and in fact he writes 2.7 on python - Andrio Skur