[Python-ideas] for/except/else syntax

Guido van Rossum guido at python.org
Wed Oct 7 05:53:49 CEST 2009


On Tue, Oct 6, 2009 at 8:46 PM, Bruce Leban <bruce at leapyear.org> wrote:
> Switching gears a bit, here's what I want:
>
> for_stmt ::= "for" target_list "in" expression_list ":" suite_loop_body
> ["except" ":" suite_if_loop_body_is_not_executed] ["else" ":"
> suite_if_loop_is_not_broken]
>
> The except and else appear in this order to make it clear that except takes
> precedence. If the loop body is not executed at all then both conditions are
> true but it obviously is only useful if except takes precedence.
> Comments?

I'm sure it's obvious to you what the except clause should do, but it
isn't to me. :-( Assuming you're not proposing we change the meaning
of else in the absence of except, and that its meaning together with
except is a logical extension of this, can you show how we should
translate a for-loop with an except clause into current Python? Say,
what would I be writing today to get the exact effect of your proposed

for i in SEQ:
  A
except:
  B
else:
  C

?

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-ideas mailing list