Buy values from the list

Asked

Viewed 80 times

0

I’m having a little problem with a list.

I have a txt with some information (log failure of a system) and wanted python to print for me this flaw with their "translation" example:

If cod_error == '1': print('Password invalidates')

and so on... follow the code:

# -*- coding: utf-8 -*-
row = []
li = []
x = 0 
y = 0
count = []
with open("Txts/test3.txt", "r") as arq:
    for linha in arq:
        if linha.find('Failed') > -1:
            li += linha.split(': ') #li recebe todos os valores separados pelo split ou seja li vai ter o valor anterior + o novo valor gerando assim uma lista conforme o numero de palavras que tem no texto
            li = [item.replace("\n", "") for item in li]

y = len(li)
#print(li[x]) #colocar [x] x = numero para printar o valor especifico

while x != y :
    #print('oi') #teste pra ver se ia executar a quanitdade de vezes correta
    print(li[x]) #Teste pra ver se iria printar os valores alocados  
    if li[x] == '1':
        print('Apenas um teste')
        break    
    x = x + 1

my problem is that Python does not seem to be entering the IF condition (if I print a li[1] the value will be '1' but if does not work with these values)

BUT ALL WAY AND BETWEEN SO MUCH: if I put so if li[x] ='Failure' it enters the condition.....

@@EDIT: If does not work when the error returned is a number, if it is a letter it works normally

  • Can you put an excerpt from the log file? I believe this code can be greatly improved. By the way, what appears on the screen due to print(li[x])?

1 answer

0


As you have noted in your question, the comparison is being performed with string 1 and not with the integer, there is a difference between if x == '1' (compares string 1) and if x == 1 (compares integer 1).

I think if you improve your if’s conditional that way already solve your problem.

  • Thanks for the help but actually my Spit was generating a n r at the end so it did not compare but already solved vlw

Browser other questions tagged

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