[Python-ideas] except expression

Rob Cliffe rob.cliffe at btinternet.com
Tue Feb 18 19:30:21 CET 2014


On 18/02/2014 15:56, Paul Moore wrote:
> On 18 February 2014 15:05, Chris Angelico <rosuav at gmail.com> wrote:
>>> Well, yes and no. There are only 2 out of the 10 syntaxes originally
>>> proposed in the PEP at the start of this thread that use a colon. I've
>>> already pointed out that I don't like a colon, so assume I said
>>> "except return 0" if you must :-)
>> Whether it's a colon or another keyword, _something_ is necessary in
>> there, if it's permissible to specify an exception type:
>>
>> sum(x[3] except IndexError 0 for x in list_of_tuples)
>> sum(x[3] except 0 for x in list_of_tuples)
>>
>> How would you parse each of those, without a separator?
> With "return" as a separator. I said that above. Was I not clear?
>
>> One option might be to have a separator that's present only when the
>> exception type is listed. For instance:
>>
>> sum(x[3] except(IndexError) 0 for x in list_of_tuples)
>> sum(x[3] except 0 for x in list_of_tuples)
>>
>> Does that sort of thing have enough support to be added to the PEP?
>> I'm not sure it gives us anything over the colon notation, which has
>> the benefit of being consistent with the statement form (and is
>> stylistically similar to lambda, so it's not grossly inappropriate to
>> an expression context)
> I remain less than happy with the colon notation, although I will
> concede that the basic
>
>      x[3] except IndexError: 0
>
> form is not horrible - it just becomes horrible very, very fast when
> people try to do anything more complicated than that.
I guess this is a subjective thing, no point in shouting too much about it.
But given that this notation is (about) the most compact for its 
generality, wouldn't any alternative become horrible even faster?
Rob Cliffe
>   On the other
> hand, none of the examples of *any* of the proposed syntaxes look
> compelling to me - they are either too simple to be realistic, or so
> complex that they should be factored out into multiple statements, in
> my view.
>
> Paul
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
>
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2012.0.2247 / Virus Database: 3705/6602 - Release Date: 02/17/14
>
>



More information about the Python-ideas mailing list