Proposed PEP for a Conditional Expression

thp at cs.ucr.edu thp at cs.ucr.edu
Tue Sep 18 12:46:20 EDT 2001


Michael Chermside <mcherm at destiny.com> wrote:
:> What do you think about this idiom?
:> 
:>>>> a=5; b=2
:>>>> c=5*[2,3][a==b]
:>>>> c
:> 10
:>>>> a=2
:>>>> c=5*[2,3][a==b]
:>>>> c
:> 15
:> 
:> Of course it doesn't solve the PEP problem's:
:>>>> def toto(x):
:> ...   print "toto"
:> ...   return x+1
:> ... 
:>>>> c=5*[toto(2),toto(3)][a==b]
:> toto
:> toto
:> 
:> But for const expressions, do you think it's obfucassed Python?
:> 

: Yes, actually, I do. It certainly doesn't "say what it means".

I have a similar objection to the syntax:

        cond( <exp1>, lambda:<exp2>, lambda:<exp3> )

Moreover it doesn't scale up to multiple tests very well:

 cond( <exp>, lambda:<exp>, lambda:cond( <exp>, lambda:<exp>, lambda:<exp> ) )

or stacked/indented version thereof.

Tom Payne




































More information about the Python-list mailing list