[Python-ideas] except expression

Ron Adam ron3200 at gmail.com
Thu Feb 20 15:13:02 CET 2014



On 02/20/2014 07:31 AM, Chris Angelico wrote:
> On Fri, Feb 21, 2014 at 12:23 AM, Ron Adam<ron3200 at gmail.com>  wrote:
>> >The expression doesn't need to be just too terms, it could be something more
>> >complex.
>> >
>> >       (except KeyError: d1[key] or d2[key] or d3[key] or None)
>> >
>> >
>> >Would give the first dictionary lookup that doesn't raise KeyError or None.
>> >
>> >Because the exception paths and data paths don't overlap, they could be
>> >dictionaries containing exception instances and it would still work.
> Okay. I think I follow. The way to spell that in the current proposal is:
>
> d1[key] except KeyError: (d2[key] except KeyError: (d3[key] except
> KeyError: None))
>
> which is rather more verbose. On the other hand, the syntax you have
> requires magic around the 'or' keyword.
>
> ChrisA


Correct.  And it would need to be able to differentiate the normal use of 
'or' and the except 'or'.  Probably with braces in some way.

Ron


















More information about the Python-ideas mailing list