My Parent class has a cat and a dog, and I need the dog to execute a function in the cat class.
Also, cat and dog need to be inner nested classes inside the parent class.
I read that dog needs to use super() to call the parent class, and then use his cat instance. But it doesn't works.
I get the error
TypeError: super(type, obj): obj must be an instance or subtype of type
_
Animal = Parent()
Animal.ThisDog.BarkToCat()
class Parent(object):
def __init__(self, *args, **kwargs):
self.ThisCat = self.cat()
self.ThisDog = self.dog()
class cat(object):
def barked(self):
return ("I better run!")
class dog(object):
def BarkToCat(self):
print(super(Parent,self).ThisCat.barked())
I cannot write dog(Parent)
class dog(Parent):
def BarkToCat(self):
print(super(Parent,self).ThisCat.barked())
... because I get the error
NameError: name 'Parent' is not defined
I'm lost. How is this done in Python?