0
I have a list of objectsconList
I want to change an attribute of an object and then write that list in a file, where each line of the file is an attribute of each object in the list.
How do I do it ?
Edit:
Code 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 in the file.
Is there any way to ask the question what code you have today? If each line in the file will be an attribute and you have a list of objects, how will you know when you finish one and start another in the file?
– Woss
is also an example of the final file format, and mainly the code you have tried to make.
– jsbueno