1

given this code :

class body:

    a = 10

    def __init__(self, sasiu, roti, Caroserie, motor):
        self.sasiu = sasiu
        self.roti = roti
        self.Caroserie = Caroserie
        self.motor = motor

class actiuni:

    def move(self, direction, speed, status):
        if status.lower() == 'start':
            print('Masina a pornit')

            if direction == 'inainte':
                print(f'Masina a inaintat cu vitaza de {speed} km\\h')
            elif direction == 'inapoi':
                print(f'Masina a a mers cu spatele cu vitaza de {speed} km\\h')

        elif status.lower() == 'stop':
            print('Masina s-a oprit')

class DetaliiMarketing:

    def __init__(self, marca, model, culoare):
        self.marca = marca
        self.model = model
        self.culoare = culoare



class masina(body, actiuni, DetaliiMarketing):

    def __init__(self, sasiu, roti, Caroserie, motor, marca, model, culoare):
        super(masina, self).__init__(sasiu=sasiu, roti=roti, Caroserie=Caroserie, motor=motor, marca=marca, model=model, culoare=culoare)
        self.myCar = {}


    def createCar(self):
        self.myCar = {'sasiu': self.sasiu,
                 'roti': self.roti,
                 'Caroserie': self.Caroserie,
                 'motor': self.motor,
                 'marca': self.marca,
                 'model': self.model,
                 'culoare': self.culoare
                 }



passatObj = masina('B6', '4', 'Sedan', '240HPTwinTurboSuperChargeDiesel', 'VolksWagen', 'B6', 'MocaBrown')
passatObj.createCar()
print(passatObj.myCar)

I'm trying to create a car object that inherits from body and actiuni class, but when i'm trying to pass init params, a typeError is returned.

Error returned:

TypeError: init() got an unexpected keyword argument 'marca'

Rolfsky
  • 63
  • 7

1 Answers1

1

You can read the detailed answers here, I will just say that in that case, you could use the following approach: Invoke __init__ for each of the base unrelated classes

class masina(body, actiuni, DetaliiMarketing):

    def __init__(self, sasiu, roti, Caroserie, motor, marca, model, culoare):
        super(masina, self).__init__(sasiu=sasiu, roti=roti, Caroserie=Caroserie, motor=motor)
        super(body, self).__init__(marca=marca, model=model, culoare=culoare)
alex_noname
  • 26,459
  • 5
  • 69
  • 86