Vote on PEP 308: Ternary Operator
Dennis Reinhardt
DennisR at dair.com
Tue Mar 4 21:36:43 EST 2003
CCE:
> Agreed. But I think you are throwing out the baby with the
> bathwater here. What is useful about the terinary operator
> is that for assignments it is clear that the lhs is uniform.
>
> z_of_useful_length = select abs(z_of_useful_length)
> case < .0001: 1.0
> else: 1.0 + z_of_useful_length
The assignment is spread across lines 1,2,3 and the comparison is on lines
1,2. I don't see the baby which is thrown out here.
DR:
> | if abs(z_of_useful_length) < .0001:
> | z_of_useful_length = 1.0
> | else:
> | z_of_useful_length += 1.0
> |
> | ... much more readable.
I think my example based on existing syntax is still more readable.
Existing syntax allowing for single lhs is:
def ternary(in_z):
if abs(in_z)< .0001: return 1.0
else: return 1.0 + in_z
z_of_useful_length = ternary(z_of_useful_length)
--
Dennis Reinhardt
DennisR at dair.com
http://www.dair.com
More information about the Python-list
mailing list