(partial) summary of ideas for the ternary operator
holger krekel
pyth at devel.trillke.net
Sat Feb 8 18:24:21 EST 2003
Michele Simionato wrote:
> Having read the thread on the ternary operator, I would like to comment
> some of the ideas that have been proposed and asking for new ones ;-)
> [skipping lots of thoughts to difficult to summarize in one line]
> ...
> P.S. the proposal by Holger Krekel's is not so bad,
>
> s=sqrt(x) except x<0: 0
Just to clarify this
a) it really was meant for exceptions not as yet
another way to spell "if"
b) it wasn't a proposal just an idea
So the 'except' idea is that you can say
result = obj.method() except AttributeError: None
which eases use of "do it and handle exceptions" instead
of look-before-you-leap. And it's easier to read
1) there are only two entities involved
2) it's obvious what is the "normal" case and is easily
spotted what the value is in case of an exception.
But as with PEP308 it has bad implications on readability
when used inside non-assignments. So i am -1 on my own
non-PEP.
cheers,
holger
More information about the Python-list
mailing list