[Python-Dev] PEP 463: Exception-catching expressions

Rob Cliffe rob.cliffe at btinternet.com
Mon Feb 24 21:56:17 CET 2014


On 22/02/2014 02:08, Glenn Linderman wrote:
> On 2/21/2014 5:06 PM, Jan Kaliszewski wrote:
>> Or even (still being my favorite):
>>
>>     msg = seq[i] except (IndexError: "nothing") 
>
> This syntax actually has a benefit: the parenthesized syntax after 
> except could become a list, to allow handling different exceptions 
> from the tried expression with different results:
>
> msg = seq[dictionary[i]] except (IndexError: "nothing", KeyError: 
> "serious problems")
It shouldn't be a true list.  We need lazy evaluation of the default 
values.  And if an unlisted exception is raised, we don't want any of 
the defaults evaluated.
Rob Cliffe
>
> And still allows nesting:
>
> msg = seq[i] except (IndexError: dictionary[i] except (KeyError: "no 
> fallback data for %s" % i))
>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/rob.cliffe%40btinternet.com
>
>
> No virus found in this message.
> Checked by AVG - www.avg.com <http://www.avg.com>
> Version: 2012.0.2247 / Virus Database: 3705/6616 - Release Date: 02/22/14
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140224/1c6b8ea4/attachment.html>


More information about the Python-Dev mailing list