[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)
-0.5
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'))
+0.5
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'))
-1
IMHO it's illogical. 'else' has completely opposite role in present
'try...except...' clauses. It'd be terribly missleading, not only
for newbies.
Cheers,
*j
--
Jan Kaliszewski (zuo) <zuo at chopin.edu.pl>
More information about the Python-ideas
mailing list