[Python-ideas] except expression

Zachary Ware zachary.ware+pyideas at gmail.com
Thu Feb 13 22:55:56 CET 2014


On Thu, Feb 13, 2014 at 12:43 PM, Amber Yust <amber.yust at gmail.com> wrote:
> Actually. What if we just reused 'try'?
>
>     foo = bar() except BazException try 'qux'
>
> This also leads naturally to chaining multiple possible fallbacks:
>
>     foo = bar() except BarException try baz() except BazException try None

This is my favorite so far, followed by s/try/return/.  I agree with
Nathan Schneider though, it does seem odd to have "try" following
"except" rather than the other way around.

What about just allowing simple try...except constructs to be
condensed to a single line?

   foo = try bar() except BarException as e e.args[0]

-- 
Zach


More information about the Python-ideas mailing list