I've been having this issue with this code, and I'm not sure why I'm still getting this TypeError here. I have the following Animal class, which is the base class for the Dog class defined below it. I want to create a Dog object which inherits from this Animal class.
Here's the Animal class:
class Animal(object):
__name = None
__height = None
__weight = None
__sound = None
def __init__(self, name, height, weight, sound):
self.__name = name
self.__height = height
self.__weight = weight
self.__sound = sound
def set_name(self, name):
self.__name = name
def set_height(self, height):
self.__height = height
def set_weight(self, height):
self.__height = height
def set_sound(self, sound):
self.__sound = sound
def get_name(self):
return self.__name
def get_height(self):
return str(self.__height)
def get_weight(self):
return str(self.__weight)
def get_sound(self):
return self.__sound
def get_type(self):
print("Animal")
def toString(self):
return "{} is {} cm tall and {} kilograms and says {}".format(self.__name, self.__height, self.__weight, self.__sound)
And then I have the following Dog class which inherits from the above Animal class:
class Dog(Animal):
__owner = None
def __init__(self, name, height, weight, sound, owner):
self.__owner = owner
super(Dog, self).__init__(self, name, height, weight, sound)
def set_owner(self, owner):
self.__owner = owner
def get_owner(self):
return self.__owner
def get_type(self):
print("Dog")
def toString(self):
return "{} is {} cm tall and {} kilograms and says {}. His owner is {}".format(self.__name, self.__height, self.__weight, self.__sound, self.__owner)
When I try to create a Dog object with the following code:
spot = Dog('Spot', 22, 11, 'Bark', 'John')
I get the following TypeError:
TypeError: __init__() takes exactly 5 arguments (6 given)
Does anyone know why I'm getting this error? I'm not really understanding what's going on here.
Thanks in advance!
Edit: After taking out the self
from the superclass, I now am getting an AttributeError: 'Dog' object has no attribute '_Dog__name'
when I try the following code:
print(spot.toString())