readlines() a file in 2 parts.

Jason Price jprice at cosette.nampaz.com
Fri Feb 8 09:08:22 EST 2002


I have several files to read that logically break into 2 parts.  It would
be much cleaner to write 2 different 'for line in file.readline() :' loops,
but the break point is different in each file, so I don't know the starting
line.  What I tried to do origionally was:

for line in file.readlines() :
   if condition :
      break
   else:
      do thing 1

for line in file.readlines()
   do thing 2

I tried both readlines and xreadlines, and neither seem to do what I'd
like.  Is there a way to do this cleanly, or should I punt, and just make
the loop more complex?

Thanks for your help;
Jason



More information about the Python-list mailing list