Graceful handling of first line

Peter Otten __peter__ at web.de
Fri Oct 8 05:43:01 EDT 2004


Egbert Bouwman wrote:

> A file is too large to fit into memory.
> The first line must receive a special treatment, because
> it contains  information about how to handle the rest of the file.
> 
> Of course it is not difficult to test if you are reading the first line
> or another one, but it hurts my feelings to do a test which by definition
> succeeds at the first record, and never afterwards.

 >>> lines = iter("abc")
>>> for first in lines:
...     print first
...     break
...
a
>>> for line in lines:
...     print line
...
b
c

Unless it hurts your feelings to unconditionally break out of a for-loop,
that is.

Peter





More information about the Python-list mailing list