I have some code to create a class hierarchy:
class LogicGate:
def __init__(self, n):
self.label = n
self.output = None
class BinaryGate(LogicGate):
def __init__(self, n):
LogicGate.__init__(self, n)
self.pinA = None
self.pinB = None
class AndGate(BinaryGate):
def __init__(self, n):
super(AndGate, self).__init__(self, n)
But when I try to create an AndGate
, an error occurs:
>>> AndGate('example')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in __init__
TypeError: BinaryGate.__init__() takes 2 positional arguments but 3 were given
What is wrong with the code? Why does the error claim that 3 arguments are being given to BinaryGate.__init__()
? How should I properly use super
instead?