So I have this python loop to read each line of a file, and I want to check if that line contains a specific string . When I run the below block of code it prints every line in the file. (which is what i want)
f = open("notifications.txt", "r+")
is_going_well = 0
for line in f.readlines():
print(line)
f.close()
return
However when i add the following "if" statement inside the for loop, it only prints one line of the file and then the loop breaks. Does anyone know why this is?
f = open("notifications.txt", "r+")
is_going_well = 0
for line in f.readlines():
print(line)
if line.contains(url):
is_going_well = 1
f.close()
return
Aucun commentaire:
Enregistrer un commentaire