Graceful handling of first line

Peter Otten __peter__ at
Sat Oct 9 08:17:14 CEST 2004

Steven Bethard wrote:

> There's still a NameError to catch if you haven't initialized line:
>>>> for line in []:
> ...     break
> ...
>>>> line
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> NameError: name 'line' is not defined

No, you would put code specific to the first line into the loop before the
> I don't much like the break out of a for loop, because it feels like a
> misuse

I can understand that.


More information about the Python-list mailing list