PEP308 :

sik0fewl xxdigitalhellxx at hotmail.com
Fri Feb 14 10:58:41 EST 2003


Roel Mathys wrote:
> Could this work?
> 
> 
> Ternary :
> 
>     if x : ( "it 's alright" , "Bye bye" )
> 
> would be the same as :
> 
>     if x :
>         "it 's alright"
>     else :
>         "Bye bye"
> 
> 
> 
> You could also find a solution like this for a switch statement:
> 
> Switch statement:
> 
>     if x :
>         {
>         15     : "it 's alright" ,
>         'hello' : "Bye bye"
>         }
>     else :
>         "Default"
> 
> would be the same as:
> 
>     if x == 15 :
>         "it 's alright"
>     elif x == 'hello' :
>         "Bye bye"
>     else :
>         "Default"
> 
> 
> bye,
> rm
> 

Most of those look more like statements than expressions.


I haven't gave any input on PEP308 yet.. so here goes:


How about something like this?

case: (cond, iftrue, iffalse)


For example:

if case: (x != 0, y / x, x):
	...

return case: (x >= 0, sqrt (x), x)

Not very 'applicable' examples, but you see how it works. And of course 
it would be lazy/short circuit.
Maybe it's not Pythonic enough, but I wouldn't mind it. Just my $0.02.

--
Ryan





More information about the Python-list mailing list