[Python-ideas] except expression

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Feb 20 05:23:27 CET 2014


Chris Angelico wrote:
> On Thu, Feb 20, 2014 at 2:13 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> 
>>   things[i] except IndexError if None
>>
>>and you have even half your wits about you, then you'll
>>notice that something doesn't make sense when you get to
>>the 'if'.
> 
> Actually, you have to keep going to see if you hit an 'else', because
> "IndexError if None else something_else" is the same as
> "something_else".

For sanity, parentheses should probably be required
for that interpretation:

    things[i] except (value if cond else other_value) if IndexError

-- 
Greg


More information about the Python-ideas mailing list