samedi 13 avril 2019

Python: Reading file line by line and comparing with target

I am trying to read a file line by line from python and comparing it with target. Can't seem to print the both variables out

target = 4234789247293487
counter = 0
with open("/Users/admin/Desktop/test3.txt", "r") as p:
for line in p:
    counter = counter + 1
    if line == target:
        print(line)
        print(counter)

Aucun commentaire:

Enregistrer un commentaire