[Python-ideas] for/else statements considered harmful

Alice Bevan–McGregor alice at gothcandy.com
Thu Jun 7 20:04:11 CEST 2012

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. ;)

	— Alice.

More information about the Python-ideas mailing list