[Python-ideas] except expression

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Feb 14 23:20:13 CET 2014


Here's another one:

    things[i] (except IndexError: 42)

This has the advantage of putting the colon inside parens,
where it's less likely to get confused with other uses of
colons in the same line (by humans, if not by the computer).

Also it might be useful to be able to say

    things.remove(i) (except ValueError: pass)

which would be equivalent to

    things.remove(i) (except ValueError: None)

but would read more smoothly in cases where you're not
interested in the value of the expression.

-- 
Greg



More information about the Python-ideas mailing list