file.txt
something in 1 line
2nd line
3rd line
my_diagram with other data
some other lines
one more line
with open('file.txt', 'r') as fp:
ad = fp.readlines()
for lines in ad:
if lines.__contains__('my_diagram'):
print('Got it')
else:
print('diagram not found')
Every time it reads a line that doesn't have the string it prints "diagram not found". I only want to print if it's not found anywhere in the file. How can I do that?
Aucun commentaire:
Enregistrer un commentaire