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

egbert egbertum at xs4all.nl
Mon Aug 16 10:02:35 EDT 2010


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 suggestion to read the itertools docs.
egbert
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991
========================================================================



More information about the Python-list mailing list