How do I print (or store) the __repr__ of the parent class? For example, consider classes like:
class Animal:
def __init__(self, n_legs):
self.n_legs = n_legs
def __repr__(self):
return f'Animal(n_legs = {self.n_legs})'
class Dog(Animal):
def __init__(self):
super(Dog, self).__init__(n_legs = 4)
def __repr__(self):
return 'Woof!'
dog = Dog()
When I call repr(dog), the returned value is Woof!. However, I want the output to be Animal(n_legs = 4), Woof!.
How can I call the __repr__ of an instance of Animal which has been inherited by dog?