[Python-ideas] except expression
Steven D'Aprano
steve at pearwood.info
Wed Feb 19 14:07:07 CET 2014
On Wed, Feb 19, 2014 at 10:17:05PM +1000, Nick Coghlan wrote:
> That said, I did suggest using the function return type annotation
> marker as a possibility, and that's not currently listed in the PEP:
>
> value = lst[2] except IndexError -> 'No value'
I missed that too. I prefer that to nearly all of the keyword based
suggestions so far. In order of most preferred to least:
+1 :
+0.9 ->
+0.5 then
-0.5 return
-1 pass, else
-> also passes the Tim Peters "grit on monitor" test.
> I do slightly prefer that to the colon based version, although we may
> want to go with the generator expression approach of always requiring
> parentheses around it (with function call parentheses counting):
>
> value = (lst[2] except IndexError -> 'No value')
I'd be happy with that solution.
--
Steven
More information about the Python-ideas
mailing list