I have a list of conList
objects that I want to change an attribute of an object and then write that list to a file, where each line of the file is an attribute of each object in the list.
How do I do this?
Edit:
Code that I have so far:
def carregarConsumiveis(self):
consList=[]
arq=open('Consumiveis.dat', 'r')
i=0
tipo=''
nome=''
codigo=''
quantidade=''
preco=''
for linha in arq:
if i==0:
tipo=linha
elif i==1:
nome=linha
elif i==2:
codigo=linha
elif i==3:
quantidade=linha
elif i==4:
preco=linha
consumivelarq=Consumivel(tipo,nome,codigo,quantidade,preco)
consList.append(consumivelarq)
i = -1
i+=1
arq.close()
return consList
I want to change an attribute of an object with a certain name, and rewrite it in the file.