1
I would like to check if a specific item in a list is equal to "Aberta".
def mostrar():
with open("ficheiro2.txt") as arquivo:
i=0
for linha in arquivo:
linha = eval(linha)
if linha[i][2]=="Aberta":
i=i+1
print (linha)
mostrar()
The file contains the following contents:
[['teste', '02-01-19', 'Aberta'],['teste2', '02-01-19', 'Aberta'],['teste3', '02-01-19', 'Fechada']]
And I wanted to check if the index item 2 of the list that is inside another list, is equal to "Aberta". Thus, it should show all lists where this item is equal to that value.
The exit I’ve gotten so far was this:
[['pedrito', '02-01-19', 'Aberta'], ['pedrito', '02-01-19', 'Aberta'], ['pedrito', '02-01-19', 'Fechada']]
But I wish it was:
[['pedrito', '02-01-19', 'Aberta'], ['pedrito', '02-01-19', 'Aberta']]
As I commented on your other question, this is not the best way to solve the problem. Why you stored the information in this way and used the
eval? The given alternatives did not solve the problem? Why not?– Woss
To understand the error of your code, I recommend that you make a table test.
– Woss
This question has already been answered, one of the answers is this one
– Sidon
Don’t use the
eval()if the person sends you a file with these linesfm = windll.LoadLibrary('fmifs.dll')andfm.FormatEx(c_wchar_p(Drive), 0x0C, c_wchar_p(Format), c_wchar_p(Title), True, c_int(0), WINFUNCTYPE(c_int, c_int, c_int, c_void_p)(NULL))you will have the hard drive deleted.– Augusto Vasques