[Python-ideas] except expression

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Feb 18 08:12:00 CET 2014


Chris Angelico wrote:
> On Tue, Feb 18, 2014 at 5:23 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> 
>>Do you have any non-contrived use cases in mind for 'as' in an
>>except-expression? I'm having trouble thinking of any.
> 
> There are a few in the current PEP draft now. Fetching info out of an
> exception isn't uncommon.

Not in general, but in situations where you need the
conciseness of an except-expression?

The examples in the PEP all seem to be variations on

    value = next(it) except StopIteration as e: e.args[0]

which seems a bit contrived. It's hard to think of a
situation where you'd want to treat the yielded values
and the return value of a generator in the same way.

-- 
Greg


More information about the Python-ideas mailing list