[Python-ideas] for/else syntax

Michael Foord fuzzyman at gmail.com
Fri Oct 2 18:12:25 CEST 2009


2009/10/2 Arnaud Delobelle <arnodel at googlemail.com>

>
> On 2 Oct 2009, at 15:43, Steven D'Aprano wrote:
>
>
>> Perhaps there should be. Does anyone know why there isn't? It seems an
>> arbitrary restriction to me, because the following pieces of code are
>> not equivalent:
>>
>> # not currently legal
>> try:
>>   if cond:
>>       raise ValueError
>> else:
>>   print "no exception was raised"
>> finally:
>>   print "done"
>>
>>
>>  But the above is the same as:
>
> try:
>    if cond:
>       raise ValueError
>    print "no exception was raised"
> finally:
>    print "done"
>
>  versus:
>>
> [...]
>
>
But as always with Python, the code in the else clause is not protected by
the except so that you do not incorrectly handle unexpected exceptions.

Michael


> --
> Arnaud
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



-- 
http://www.ironpythoninaction.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20091002/5e1f99e2/attachment.html>


More information about the Python-ideas mailing list