Graceful handling of first line

Josiah Carlson jcarlson at uci.edu
Fri Oct 8 17:41:11 CEST 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