regular expression or parser ?

Kent Johnson kent at
Tue Jan 3 14:21:59 CET 2006

Forced_Ambitions wrote:
> Hi,
> I m a novice to python..I m stuck in a problem and need some help.
> i m trying to extract data  between the line "start operation" and the
> line "stop operation"
> from a txt file. and then to fill it under different columns of an
> excel sheet.

A simple stateful loop may be enough for the parsing part. Something 
like this:

f= open('data.txt')

   while True:
     # Skip to the next start
     while != 'start operation':

     # process lines
     while True:
       line =
       if line == 'stop operation':
       # process line

except StopIteration:

If you only have one block to process and you are confident it will 
always be present then the try / except and outer while loop are not needed.

If you can live with CSV output instead of XLS then see the csv module 
for the processing part.


More information about the Python-list mailing list