Buy list values

0

I'm having a problem with a list.

I have a txt with some information (log failure of a system) and I wanted python to print to me these faults with the "translation" of them example:

If cod_erro == '1':    print ('Invalid password')

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 appear to be entering the IF condition (if I start li [1] the value will be '1' but if it does not work with those values)

BUT ALL THE WAY AND BETWEEN: if I put it that way if li [x] == 'Failure' it goes into condition .....

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

    
asked by anonymous 11.07.2018 / 19:43

1 answer

1

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

I think if you improve the conditional of your if in this way already solves your problem.

    
11.07.2018 / 21:46