[Python-ideas] try-else without except or finally
Matt Joiner
anacrolix at gmail.com
Mon Nov 14 20:34:23 CET 2011
To be fair it's not a new construct, it's loosening the constraints on
an existing one.
else has the same use as in the for and while compound statements:
It's executed if the first block completes "successfully". An
exception being thrown in a try block, cancels execution of the "else"
block, the same way as "break" in the for and while statements.
I have a problem with the idea now in that:
try:
a
else:
b
is the same as:
try:
a
b
else:
pass
and even:
try:
pass
else:
a
b
in every possible interpretation. This isn't possible with if, for,
while, try/except, and try/finally compound statements, all of which
alter the meaning in *some* way.
So I maintain that the else block could be made allowable even without
an except block, but it would be purely for convenience. I don't think
it's worth it anymore.
Cheers all for consideration.
On Tue, Nov 15, 2011 at 1:25 AM, Giampaolo Rodolà <g.rodola at gmail.com> wrote:
> 2011/11/14 alex23 <wuwei23 at gmail.com>:
>> On Nov 11, 1:53 am, Guido van Rossum <gu... at python.org> wrote:
>>> +1. Nobody's going to understand try...else... on first reading.
>>
>> On the other hand, no one properly understands for...else... when
>> first encountering it either.
>
> I see no value in adding another hardly understandable construct.
> Plus, in my mind try/else appears to be logically different than
> for/else (which I find very useful).
> -1
>
> --- Giampaolo
> http://code.google.com/p/pyftpdlib/
> http://code.google.com/p/psutil/
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
More information about the Python-ideas
mailing list