A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2009-August/091071.html below:

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

[Python-Dev] (try-except) conditional expression similar to (if-else) conditional (PEP 308) [Python-Dev] (try-except) conditional expression similar to (if-else) conditional (PEP 308)MRAB python at mrabarnett.plus.com
Fri Aug 7 01:33:49 CEST 2009
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')

In other words, some_check() returns an exception _class_.

 >>> def get_exception():
     return ValueError

 >>> try:
     x = float("")
except get_exception():
     print "not a float"


not a float

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4