[Python-ideas] except expression
Ron Adam
ron3200 at gmail.com
Thu Feb 20 08:52:02 CET 2014
On 02/19/2014 08:58 PM, Greg Ewing wrote:
> Another idea:
>
> things[i] or else None if IndexError
>
> You can't claim that the exception is in the wrong place
> in relation to the 'except' keyword, because there is no
> 'except' keyword!
By adding a __bool__ attribue to exceptions that always returns False, you
can get some of that, but it has the same issues that logic operators have
when a normally False item is also valid data.
To get around that we would need a differently based logic system where the
caught exception(s) are the only False values.
Exception logic with False as an exception.
e1 and e2 or e3
Translate to this...
try:
e1
e2
except False:
e3
Then with IndexError.
(except IndexError: things[i] or None)
Cheers,
Ron
More information about the Python-ideas
mailing list