Mandatory indenting (Was: Vote on PEP 308: Ternary Operator)
Clark C. Evans
cce at clarkevans.com
Tue Mar 4 06:24:37 EST 2003
>From my usage pattern, what is missing in python is a clear way
to indicate (for the reader) a conditional assignment. Certainly
this is possible, but it isn't that easy to read:
if quantity > 0: exit = "door"
else: exit = "doors"
I'd rather have something like...
exit = (if quantity > 0: 'door'
else: 'doors')
However, the idea of moving the 'else' part onto the 1st line
is where it gets ugly and where I cry uncle. Here are the
examples with mandatory parens and new line...
x = "door" + (if quantity > 1: 's'
else: '')
data = (if hasatttr(s, 'open'):
s.readlines()
else:
s.split()
)
z = 1.0 + (if abs(z) < .0001: 0
else: z)
t = v[index] = (if t <= 0:
t-1.0
else:
-sigma / (t+1.0)
)
return (if len(s) < 10: linesort(s)
else: qsort(s))
I think that these are probably more clear than the
traditional if/else statement.
Clark
P.S. That said, I like the previous select/case proposal better.
More information about the Python-list
mailing list