[Python-Dev] "and" and "or" operators in Py3.0
nidoizo at yahoo.com
Tue Sep 20 08:00:30 CEST 2005
Raymond Hettinger wrote:
> I propose that in Py3.0, the "and" and "or" operators be simplified to
> always return a Boolean value instead of returning the last evaluated
Please no. I find things like:
def __cmp__(self, other):
return (cmp(self.a, other.a) or
cmp(self.b, other.b) or
But I don't know how this can be useful for "and" however.
> 1) The construct can be error-prone. When an error occurs it can be
> invisible to the person who wrote it. I got bitten in published code
> that had survived testing and code review:
> def real(self):
> 'Return a vector with the real part of each input element'
> # do not convert integer inputs to floats
> return self.map(lambda z: type(z)==types.ComplexType and z.real or
As others pointed, if lambda is to be possibly removed in py3.0, it
would be better to have an example not using it.
FWIW, I've never had a problem with that, but however I use the feature...
Quite the opposite actually, I even though about overriding and and or
to build event-driving expression, which I can't... well, forget about
> 2) When going back and forth between languages, it is easy to forget
> that only Python returns something other than a boolean.
Well, there's a lot of things I miss from Python when going back and
forth between languages. You need a better argument to convince me to
also miss that one in Python;)
I think it's not reasonable to remove the feature without adding a ?:
syntax. I personally like the status quo.
More information about the Python-Dev