[Python-ideas] exception based conditional expression, similar to if-else conditional expression
mcaninch at lanl.gov
Thu Aug 20 16:27:26 CEST 2009
> -1, if this goes through it will be extended to all other compound
> statements over time and we'll end up with 2 or 3 ways to do every
> A much better idea would be to find a way to make all compound
> statements into expressions, future-proofing the decision and avoiding
> the redundancy between "compound statement statement" and "compound
> statement expression".
Python's list of compound statements is pretty thin (just 7),
and 4 of these already have expression forms.
for ==> list comprehension, iterator expression
while ==> list comprehension, iterator
if ==> if-else conditional expression
def ==> already have lambda expressions
try ==> my proposal
class ==> Okay, so this one doesn't have a compound statement,
but where would you use it?
with ==> I haven't had an occasion to use with,
so can't think of an example where it could
be useful as a compound expression.
Seems to me try-except is kind of sticking out here, and I've
tried to show what I think are natural and common places where
a try-except expression would be appropriate.
Jeffrey E. McAninch, PhD
Los Alamos National Laboratory
Email: mcaninch at lanl.gov
More information about the Python-ideas