[Python-Dev] PEP 463: Exception-catching expressions
ethan at stoneleaf.us
Sat Feb 22 01:42:36 CET 2014
On 02/21/2014 11:04 AM, Yury Selivanov wrote:
> On 2/20/2014, 10:15 PM, Chris Angelico wrote:
>> * list.pop() - no way to return a default
> We can fix that in 3.5.
How many are you going to "fix"? How are you going to "fix" the routines you don't control?
>> * seq[index] - no way to handle a bounds error
> We can add 'list.get(index, default)' method, similar to
> 'Mapping.get'. It's far more easier than introducing new
When I have to keep writing the same code over and over and aver again, I find a better way to do the job. In this
case, an exception expression does quite nicely.
> I also searched how many 'except IndexError' are in
> the standard library code. Around 60. That's a rather
> low number, that can justify adding 'list.get' but not
> advocate a new syntax.
And roughly 200 of KeyError, another couple hundred of ValueError...
This is not just about better handling of [missing] default values, but of better exception handling. This PEP adds the
ability to use a scalpel instead of a sledge hammer.
More information about the Python-Dev