[Python-ideas] try-else without except or finally

Ethan Furman ethan at stoneleaf.us
Mon Nov 14 21:23:02 CET 2011


Chris Kaynor wrote:
> While it is redundant to allow else without except, I would agree that
> it should be allowed for the same reason that else is allowed on for
> and while without a break. The alternative would be to make the later
> illegal. Either seems reasonable, however the former maintains
> backwards compatibility, while the later breaks it.

if / else: if the 'if' condition is False, run the 'else'

for / else: when the 'for' condition is False, run the 'else'

while / else: when the 'while' condition is False, run the 'else'

try /except / else: when the 'except' condition is False, run the 'else'

try / else: when the 'try' condition is False, run the 'else' ??

To be consistent, the 'else' in a try/else would basically be an 'except 
Exception' -- it completely reverses the meaning of the 'else' in a 
try/except/else block.

~Ethan~



More information about the Python-ideas mailing list