0
class A(object):
    def __init__(self, id):
        print("in A")


class B(object):
    def __init__(self, id1, id2):
        print("In B")

class C(A,B):
    def __init__(self, id1, id2):
        super(C, self).__init__(id1)
        super(C,self).__init__(id1,id2)

I am calling C's object as C(1,2).

It throws error:

TypeError: __init__() takes exactly 2 arguments (3 given)

May I know how to call both parent class' __init__ from C's __init__?

Pavel
  • 7,436
  • 2
  • 29
  • 42
rachitmanit
  • 324
  • 3
  • 12
  • I went ahead and marked this as a duplicate because if the top answer there doesn't help you, the linked article certainly ought to. Note that the person answering is a major contributor on the Python dev team, so this is pretty authoritative :) – Karl Knechtel Dec 26 '17 at 17:07

1 Answers1

-1

Try this:

class C(A, B):
    def __init__(self, id1, id2):
        A.__init__(self, id1)
        B.__init__(self, id1, id2)
lpozo
  • 598
  • 2
  • 9