How to create separate objects from a loop?

Asked

Viewed 250 times

1

class linha ():
    def __init__ (self, texto):
        self.texto = texto
def criador ():
    for i in range(5):
        a = raw_input ('escreva: ')
        global objetoi
        objetoi = linha (a)

How do I make the function criador generates a different object with each interaction in the loop for?

1 answer

1


Put inside a list:

class linha ():
    def __init__ (self, texto):
        self.texto = texto
def criador ():
    lista = []
    for i in range(5):
        a = raw_input ('escreva: ')
        lista.append(linha(a))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.