[Python-ideas] except expression

Chris Angelico rosuav at gmail.com
Thu Feb 13 04:16:00 CET 2014


On Thu, Feb 13, 2014 at 2:08 PM, Amber Yust <amber.yust at gmail.com> wrote:
> Why not use yield instead of else?
>
> foo = something() except BazException yield "bar"

yield is already an expression. It'd be theoretically and
syntactically valid (if a little weird) to use yield "bar" in place of
the name BazException; you'd yield "bar" to your caller, then whatever
exception gets sent in would be the one tested for. I honestly cannot
conceive of any situation where this would actually be useful, but it
does make it a little tricky to reuse that keyword :)

ChrisA


More information about the Python-ideas mailing list