[Python-ideas] for/except/else

Sven R. Kunze srkunze at mail.de
Fri Mar 3 04:16:36 EST 2017


On 03.03.2017 09:47, Wolfgang Maier wrote:
> However, the fact that else exists generates a regrettable asymmetry 
> in that there is direct language support for detecting one outcome, 
> but not the other.
>
> Stressing the analogy to try/except/else one more time, it's as if 
> "else" wasn't available for try blocks. You could always use a flag to 
> substitute for it:
>
> dealt_with_exception = False
> try:
>     do_stuff()
> except:
>     deal_with_exception()
>     dealt_with_exception = True
> if dealt_with_exception:
>     do_stuff_you_would_do_in_an_else_block()

Even worse when we think about the "finally" clause.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170303/edf1b4e9/attachment.html>


More information about the Python-ideas mailing list