Graceful handling of first line
Gerrit
gerrit at nl.linux.org
Fri Oct 8 05:52:00 EDT 2004
Peter Otten wrote:
> >>> 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.
How about:
>>> lines = iter("abc")
>>> first = lines.next()
>>> print first
a
>>> for line in lines:
... print line
...
b
c
Would hurt less feeling I presume.
Gerrit.
--
Weather in Twenthe, Netherlands 08/10 11:25:
11.0°C Few clouds mostly cloudy wind 0.9 m/s None (57 m above NAP)
--
In the councils of government, we must guard against the acquisition of
unwarranted influence, whether sought or unsought, by the
military-industrial complex. The potential for the disastrous rise of
misplaced power exists and will persist.
-Dwight David Eisenhower, January 17, 1961
More information about the Python-list
mailing list