[Python-3000] Exception Expressions

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Sep 1 04:39:37 CEST 2006


Calvin Spealman wrote:

> Other example use cases:
> 
>     # Fallback on an alternative path
> 
>     # Handle divide-by-zero

or get by with index() instead of find():

    s.index("foo") except -1 if IndexError # :-)

 >     open(filename) except open(filename2) if IOError

One problem is that it doesn't seem to chain
all that well. Suppose you had three files to
try opening:

   open(name1) except (open(name2) except open(name3) if IOError) if IOError

Maybe it would be better if the exception type
and alternative expression were swapped over.
Then you could write

   open(name1) except IOError then open(name2) except IOError then open(name3)

Still rather unwieldy though. -0.7j, I think
(the j to acknowledge that this is an imaginary
proposal.:-)

-- 
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | Carpe post meridiem!          	  |
Christchurch, New Zealand	   | (I'm not a morning person.)          |
greg.ewing at canterbury.ac.nz	   +--------------------------------------+


More information about the Python-3000 mailing list