When the first line of a file tells something about the other lines

2010-08-16 Thread Egbert Bouwman
Often the first line of a file tells how to read or interpret the other lines. Depending on the result, you then have to ... - skip the first line, or - treat the first line in another special way, or - treat the first line in the same way as the other lines. I can handle this by opening the file

Re: When the first line of a file tells something about the other lines

2010-08-16 Thread Peter Otten
Egbert Bouwman wrote: Often the first line of a file tells how to read or interpret the other lines. Depending on the result, you then have to ... - skip the first line, or - treat the first line in another special way, or - treat the first line in the same way as the other lines. I can

Re: When the first line of a file tells something about the other lines

2010-08-16 Thread egbert
On Mon, Aug 16, 2010 at 11:59:57AM +0200, Peter Otten wrote: with open(filename) as lines: first_line = next(lines, ) if special(first_line): # ... else: lines = itertools.chain([first_line], lines) for line in lines: # ... Beautiful. And a nice