[Python-ideas] (try-except) conditional expression similar to (if-else) conditional (PEP 308)

Jan Kaliszewski zuo at chopin.edu.pl
Fri Aug 7 02:15:56 CEST 2009

> Syntax Ideas:
>     Option 1:
>         x = float(string) except float('nan') if ValueError
>         op(float(string) except float('nan') if ValueError)

I wouldn't mix up 'if' word with 'except' -- there are different concepts.

>     Option 2:
>         x = float(string) except ValueError: float('nan')
>         op(float(string) except ValueError: float('nan'))

IMHO seems to be the best of the propositions. I'd add to it optional
as (like in present 'try:... except Exc as exc:...')

>     Option 3:
>         x = float(string) except ValueError else float('nan')
>         op(float(string) except ValueError else float('nan'))

IMHO it's illogical. 'else' has completely opposite role in present
'try...except...' clauses. It'd be terribly missleading, not only
for newbies.


Jan Kaliszewski (zuo) <zuo at chopin.edu.pl>

More information about the Python-ideas mailing list