[Python-ideas] except expression

Chris Angelico rosuav at gmail.com
Thu Feb 20 09:36:28 CET 2014


On Thu, Feb 20, 2014 at 6:52 PM, Ron Adam <ron3200 at gmail.com> wrote:
>
>
> 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)

I've read your post a few times and am still a bit lost. How would the
above be evaluated?

ChrisA


More information about the Python-ideas mailing list