[Python-ideas] Control Flow - Never Executed Loop Body

Steven D'Aprano steve at pearwood.info
Sun Mar 20 21:44:33 EDT 2016


On Sun, Mar 20, 2016 at 07:12:58PM +0100, Sven R. Kunze wrote:

> for item in my_iterator:
>      # do per item
> empty:
>      # do something else

"empty" is a poor choice, as I expect that it will break a lot of code 
that already uses it as a variable.

if empty:
   ...



> *Keyword*
> Keywords under consideration have been in (an attempt of dispassionate) 
> order of preference:
> 1) empty -> most obvious, most people responded with a solution to solve 
> the intended problem
> 2) else -> already taken but to some would be the preferred one
> 3) or -> as alternative if a new keyword is too much

I'm not too keen on the look of "or" for this:

for x in iterable:
    block
or:
    alternative


but I think it's the least worst of the proposed keywords.



> 4) except -> as alternative if a new keyword is too much

I think that "except" completely fails to describe what the keyword 
does, and it will give some people the misunderstanding that it catches 
errors in the body of the for-loop.


-- 
Steve


More information about the Python-ideas mailing list