[Python-ideas] "while ... try" - block or "for ... try" - block

Arnaud Delobelle arnodel at gmail.com
Wed Jan 11 18:06:58 CET 2012


2012/1/11 Manuel Bärenz <manuel at enigmage.de>:
> I propose two new control flows for Python:
>
> "while ... try":
>
> while expr try:
>    suite1
> except SomeException:
>    suite2
> else:
>    suite3
>
> This executes suite1 as long as handled exceptions are thrown and expr
> is True.
> * If an unhandled exception is thrown, it passes the exception on to the
> surrounding or the stack.
> * If no exception occurs, life goes on as normal, suite3 is executed and
> execution goes on afterwards.
>
> The control flow is thus equivalent to:
>
> while expr:
>    try:
>        suite1
>    except SomeException:
>        suite2
>    else:
>        suite3
>        break

Aside from anything else, there is the problem that

while:
    suite
else:
    suite

is already valid Python

Your proposed syntax changes the semantics of "else" after "while"
(and the same applies to "for ...  else".

-- 
Arnaud



More information about the Python-ideas mailing list