[Python-ideas] for/else statements considered harmful

MRAB python at mrabarnett.plus.com
Thu Jun 7 20:18:12 CEST 2012


On 07/06/2012 19:04, Alice Bevan–McGregor wrote:
> On 2012-06-07 16:29:01 +0000, Mike Meyer said:
>
>>  On Thu, 7 Jun 2012 11:52:10 -0400
>>  Alice Bevan–McGregor<alice at gothcandy.com>  wrote:
>>
>>>  Now for loops perfectly match try/except/else/finally!>:D  (Like
>>>  exception handling, finally would be called even with an inner return
>>>  from any of the prior sections.)
>>
>>  For for (and don't forget while) loops, finally is pointless. It's the
>>  same as code after the loop. For try, finally runs even if there's an
>>  exception, which isn't true of that code.
>
> I really should use parenthesis less as obviously people don't read the
> content between them.  (Not just you, I'm afraid! ;^)  If it weren't a
> useful feature (for/empty) I'm unsure as to why so many template
> engines implement it even though in most of them you _can_ utilize a
> sentinel value; at least, in the ones that allow embedded Python code.
>
> Alas, the BDFL has spoken, however.  (Getting shot down was not
> unexpected despite the occasional +1000. ;)
>
It was the comment about the "finally" clause always running which was the
problem, not about running a clause when there was an empty sequence.



More information about the Python-ideas mailing list