FixedPoint
Mark McEahern
marklists at mceahern.com
Sun Feb 10 23:08:46 EST 2002
[Jason Orendorff]
> Yep. If you know what's in _norm() you can do better than I
> can. :) Also, you might pull the first return statement out
> of the try.
_norm basically pulls the number and the precision out of the FixedPoint
instances. So that would give us this:
def __cmp__(self, other):
try:
xn, yn, p = _norm(self, other)
except TypeError:
xn, yx = self, float(other)
return cmp(xn, yn)
The only problem is: It doesn't work with other as None because this fails:
float(None)
which leads us back to testing for None:
def __cmp__(self, other):
if other is None:
return 1
try:
xn, yn, p = _norm(self, other)
except TypeError:
xn, yx = self, float(other)
return cmp(xn, yn)
I'm inclined at this point to think I'd only do this if I couldn't change
the code that's doing the foo == None.
// mark
More information about the Python-list
mailing list