Graceful handling of first line
Peter Otten
__peter__ at web.de
Sat Oct 9 02:17:14 EDT 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
break.
> I don't much like the break out of a for loop, because it feels like a
> misuse
I can understand that.
Peter
More information about the Python-list
mailing list