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
1
  • The while loop condition will not change Commented Aug 25, 2018 at 16:29

2 Answers 2

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!

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.