vendredi 16 février 2018

Python3 For-Loop and If-Statement trouble

I just wrote some code which should go through each line of a file and should call another function if the number after the first word of the line is a 1.

The file looks like this:
Button0 1
Button1 0
Motion 0
Order 0

My code:

currLog = open(log,"r") #Open current Log-File
    for line in currLog:    #Loop through each Line
        pos = line.split(" ")   #Split line into Name(pos0) and Answer(pos1)
        print(pos[1])
        if (pos[1] == "0"):
            print("Button0")

Shell-Ouput:

1

0

0

0

Button0

Like you see it only enters the if-statement at the last line

Already thankful for help.

Aucun commentaire:

Enregistrer un commentaire