"Eduardo Vieira" <eduardo.su...@gmail.com> wrote
The other day I was writing a script to extract data from a file
from
the line where a text is found to the end of the file.
The standard pattern here is to use a sentinel, in pseudo code:
def checkLine(line, start='',end=''):
if (start in line) or (end in line): return True
else: return False
startPattern = 'some string (or regex)'
endPattern = 'a concluding string or regex'
sentinel = False
while True
read line from file
sentinel = checkLine(line, startPattern, endPattern)
if sentinel:
processLine(line)
You can simplify or complexify that in many ways, and you can
add a break check to speed it up if you only expect to process
a few lines.
And checkLine can be as simple or as complex as you like.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor