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

Dino Viehland dinov at microsoft.com
Fri Aug 7 02:01:23 CEST 2009


MRAB wrote:
> Dino Viehland wrote:
> > On option 1 is this legal then?
> >
> > x = float(string) except float('nan') if some_check() else float('inf') if
> ValueError
> >
> Well, is this is legal?
>
>      try:
>          x = float(string)
>      except some_check():
>          x = float('nan')
>      except ValueError:
>          x = float('inf')
>

I was thinking this was would be equal to:

x = float(string) except (float('nan') if some_check() else float('inf')) if ValueError




More information about the Python-Dev mailing list