I have these 2 classes:
from avatar import Avatar
class Caster(Avatar):
def __init__(self, name, life, strength, protection, mana):
super().__init__(name, life, strength, protection)
self._mana = mana
and:
from avatar import Avatar
class Melee(Avatar):
def __init__(self, name, life, strength, protection, shield):
super().__init__(name, life, strength, protection)
self._shield = shield
Both of them inherit from:
class Avatar:
def __init__(self, name, life, strength, protection):
self._name = name
self._life = life
self._strength = strength
self._protection = protection
Now I want to create a new class which inherits from both Caster and Melee
from melee import Melee
from caster import Caster
class Chaman(Melee, Caster):
def __init__(self, name, life, strength, protection, shield, mana):
Melee().__init__(self, name, life, strength, protection, shield)
Caster().__init__(self, mana)
This new class combines elements from Melee and Caster. When I execute this and try to create new Chaman objects, it gives me this error:
TypeError: __init__() missing 5 required positional arguments: 'name', 'life', 'strength', 'protection', and 'shield'
Caster.__init__to take all these arguments, but when you callCaster().__init__inChaman.__init__you don't provide them. AlsoCaster()already implicitly callsCaster.__init__(with no arguments at all), so you meantCaster.__init__(...).superwith explicit base class references.Chaman.__init__should just callsuper().__init__(name, life, strength, protection, shield)and let the base classes figure things out. You might have to swap the base classes, though.