Posted under » Python on 3 December 2025
There may be a time when you want to look for a word line by line in a text file. Here is one way
with open(r'email.txt', 'r') as fp:
lines = fp.readlines()
for row in lines:
word = 'gaybo011@' # String to search for
if row.find(word) != -1:
print('String exists in file')
print('Line Number:', lines.index(row))