Graceful handling of first line
Josiah Carlson
jcarlson at uci.edu
Fri Oct 8 11:41:11 EDT 2004
> >>> lines = iter("abc")
> >>> first = lines.next()
> >>> print first
> a
> >>> for line in lines:
> ... print line
> ...
> b
> c
>
> Would hurt less feeling I presume.
Unless it was empty, then you'd get the dreaded StopIteration!
IMO, unconditionally breaking out of a for loop is the nicer way of
handling things in this case, no exceptions to catch.
- Josiah
More information about the Python-list
mailing list