Graceful handling of first line
jcarlson at uci.edu
Fri Oct 8 17:41:11 CEST 2004
> >>> lines = iter("abc")
> >>> first = lines.next()
> >>> print first
> >>> for line in lines:
> ... print line
> 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.
More information about the Python-list