Я довольно новичок в Python и пытаюсь понять множественное наследование. Ниже у меня есть код, где мне нужно создать массив из животных .
- животных может быть одомашненных и Кошачий
- A Тигр Кошачий Животное
- A Кошка это Одомашненный & Кошачий Животное
Вот классы:
class Animal:
def __init__(self, birthDate, type, name, numOfLegs):
self.birthDate = birthDate
self.type = type
self.name = name
self.numOfLegs = numOfLegs
class Domesticated(Animal):
def __init__(self, birthDate, type, name, numOfLegs, lastVetCheck):
super().__init__(birthDate, type, name, numOfLegs)
self.lastVetCheck = lastVetCheck
class Feline(Animal):
def __init__(self, birthDate, type, name, numOfLegs, mustacheLength):
super().__init__(birthDate, type, name, numOfLegs)
self.mustacheLength = mustacheLength
class Cat(Feline, Domesticated):
def __init__(self, mustacheLength, numOfLegs, name, type, bDate, vetDate):
Feline.__init__(self, bDate, type, name, numOfLegs, mustacheLength)
Domesticated.__init__(self,bDate, type, name, numOfLegs, vetDate)
class Tiger(Feline):
def __init__(self, birthDate, type, name, numOfLegs, mustacheLength):
super().__init__(birthDate, type, name, numOfLegs, mustacheLength)
Rese из code:
animal_array = []
my_cat = Cat('4', '4', 'Tom', 'Mammal', '1.2.3', '3.4.5')
my_animal = Animal('6.7.8', 'Reptile', 'Rafael', '4')
my_tiger = Tiger('1.1.1', 'Mammal', 'Tiger', '4', '9')
animal_array.append(my_cat)
animal_array.append(my_animal)
animal_array.append(my_tiger)
Я получаю эту ошибку:
Traceback (most recent call last):
File "C:/Users/Name/PycharmProjects/Pandas/test.py", line 33, in <module>
my_cat = Cat('4', '4', 'abc', 'mammal', '1.2.3', '3.4.5')
File "C:/Users/Name/PycharmProjects/Pandas/test.py", line 23, in __init__
Feline.__init__(self, bDate, type, name, numOfLegs, mustacheLength)
File "C:/Users/Name/PycharmProjects/Pandas/test.py", line 17, in __init__
super().__init__(birthDate, type, name, numOfLegs)
TypeError: __init__() missing 1 required positional argument: 'lastVetCheck'
Теперь я уверен, что это простая проблема, возможно, мои классы структурированы плохо, хотя я понятия не имею, что делать фикс. Я уверен, что могу использовать любые советы по структурированию, так как я довольно плохо знаком с OO.