[Python] python multiple inheritance passing arguments to constructors using super

Discussão em 'Python' iniciado por Stack, Março 22, 2025.

  1. Stack

    Stack Membro Participativo

    Consider the following snippet of python code

    class A(object):
    def __init__(self, a):
    self.a = a

    class B(A):
    def __init__(self, a, b):
    super(B, self).__init__(a)
    self.b = b

    class C(A):
    def __init__(self, a, c):
    super(C, self).__init__(a)
    self.c = c

    class D(B, C):
    def __init__(self, a, b, c, d):
    #super(D,self).__init__(a, b, c) ???
    self.d = d


    I am wondering how can I pass a, b and c to corresponding base classes' constructors.

    Continue reading...

Compartilhe esta Página