0

I want to call an object of another class in my class but when i run the code it says: RecursionError: maximum recursion depth exceeded

Any ideas of what error im making?

This is my code:

class Anden(Estacion):

    def __init__ (self,ID):

        self.ID=ID
        self.filas_anden=[0,0,0,0,0,0,0,0,0,0]
        self.puertas = []

        while len(self.puertas) < 10:
            puerta = Puerta(len(self.puertas))


    def asignar_fila(self, pasajero):
        aux=10000000000
        puerta_asignada = min(filas_anden)

        for i in range(10):            
            if aux > self.puertas[i].total_fila:
                aux = self.puertas[i].total_fila
                fila_asignada = i
        pasajero.fila_actual = i 
        self.filas_anden[i] +=1
        self.puertas[i].append(pasajero)


class Puerta(Anden):

    def _init_ (self,ID):
        self.ID = ID
        self.lista_pasajeros = []
        self.total_fila = 0


    def ingresa_pasajero_fila(self, pasajero):
        self.lista_pasajeros.append(pasajero)
        self.total_fila = self.total_fila + 1

    def remover_pasajero_fila(self, pasajero):
        self.lista_pasajeros.remove(pasajero)
        self.total_fila = self.total_fila - 1
Nic3500
  • 8,144
  • 10
  • 29
  • 40

2 Answers2

1

So a few things. You made a typo in your Puerta constructor method. You're using _init_ instead of __init__, so when you initialize a Puerta object it's falling back to the constructor of its base class, Anden. That's what's causing this recursion error. Secondly, in your Anden constructor method, I think what you're trying to achieve is the following

def __init__ (self,ID):
    self.ID=ID
    self.filas_anden=[0,0,0,0,0,0,0,0,0,0]
    self.puertas = []

    while len(self.puertas) < 10:
        self.puertas.append(Puerta(len(self.puertas)))

In your current implementation, you're just setting an arbitrary variable puerta to a Puerta object which doesn't change the puertas list of your Anden instance and the while loop keeps going forever. Hope this helps!

prithajnath
  • 2,000
  • 14
  • 17
0

You're having the same problem as Recursion error with class inheritance. A solution would be to make Puerta inherit from a base class common to Anden, instead of inheriting from Anden directly.

al-dev
  • 256
  • 2
  • 8