I have a class(call it ClassC) where one of the attributes is another class(call it ClassB). ClassB actually needs data from ClassC to initialize itself, so I pass ClassC to ClassB using the following syntax:
class ClassC(object):
def __init__(self):
self.val = 8
self.derived_class = ClassB(self)
I'm seeing an error that complains about init() not taking any parameters, but I'm just not seeing where the issue could be arising from. Am I not using super() in the correct way so that ClassB initializes its base class,ClassA, as well?
Traceback (most recent call last): File "python", line 18, in File "python", line 15, in init File "python", line 9, in init TypeError: object.init() takes no parameters
I have reproduced the code below, or you can run it here.
class ClassA(object):
def __init__(self, initial_class):
self.val = None
self.initial_class = initial_class
class ClassB(ClassA):
def __init__(self, initial_class):
super(ClassA, self).__init__(initial_class)
self.val = 7
class ClassC(object):
def __init__(self):
self.val = 8
self.derived_class = ClassB(self)
c = ClassC()