with open('text.txt', 'rt') as file:
for index, line in enumerate(file):
if pattern in line:
print(index)
search_string = 'mytext'
with open("myfile.txt") as f:
n = 0
for line in f:
n += 1
if search_string in line:
print(search_string, 'found on line', n)