I am trying to write a program that prints every line of the file until a certain string is found. The file is a plain text file. I put the sample context at the top of the code. But the function gets stuck in an infinite loop. I don't want to use a break statement so I have no idea how to fix it.
'''Where he at
There he go
Peanut butter jelly
Do the peanut butter jelly, peanut butter jelly
Peanut butter jelly with a baseball bat'''
def limit_read(filename):
string = 'baseball'
for line in f:
while line.find(string) == -1:
print line