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

Jeff McAninch mcaninch at lanl.gov
Thu Aug 6 16:36:45 CEST 2009

Nick Coghlan wrote:
> Option 1:
> Change the relative order of the clauses by putting the exception
> definition last:
>   x = float(string) except float('nan') if ValueError
>   op(float(string) except float('nan') if ValueError)
> I actually like this one (that's why I listed it first). It gets the
> clauses out of order relative to the statement, but the meaning still
> seems pretty obvious to me.
Since I don't know the parser coding, I won't comment on the relative implentability (implementableness?) of the syntax options that Nick,
P.J. and Raymond suggested.  But all seem readable and debugable.

Nick's option 1 seems like it might be the most understandable to 
a Python novice.

Would the full syntax include multiple Exceptions after the "if"?


Jeffrey E. McAninch, PhD
Physicist, X-2-IFD
Los Alamos National Laboratory
Phone: 505-667-0374
Email: mcaninch at lanl.gov

More information about the Python-Dev mailing list