creating an inner loop IS what you want to do, but
-
while not 'endin' in line:
-
pass
-
hangs because you never read any new lines.
I still recommend this inside the if block (you have found what you want copied)
-
outfile.write(line)
-
try:
-
while True:
-
line = infile.next()
-
outfile.write(line)
-
if 'endin' in line:
-
break
-
except StopIteration:
-
print 'never found endin'
-
This way you get the first line written to the outfile plus the line that contains 'endin'.