I would like to go to my file that contains the following
['teste1', '27-12-18', '12/5/2015', 'Aberta']
['teste2', '27-12-18', '6/7/7', 'Aberta']
['teste3', '27-12-18', '12/5/6', 'Fechada']
and only show if the 3 field is Open I have the following code;
Writing to file:
def annexsentence():
data_inicio=input("Nome da Tarefa :")
data_final=input("Data Final :") #placeholder ano-mes-dia
data_atual = datetime.datetime.now().strftime("%d-%m-%y")
estado="Aberta"
lista=[data_inicio,str(data_atual),str(data_final),estado]
annexsentence=open("ficheiro.txt","a")
annexsentence.write(str(lista)+"\n")
annexsentence.close()
annexsentence()
Reading the file:
def mostrar():
#ler linha a linha
with open("ficheiro.txt") as arquivo:
for linha in arquivo:
if linha[3]=="Aberta":
print (linha)
else:
print("ola")
mostrar()
Can someone explain what I should do to fix it?
If you do print(linha[3])
return and test and get linha[0]
[
appears