fixedpoint cmp conundrum
Robert Brewer
fumanchu at amor.org
Tue May 4 02:36:48 EDT 2004
Tim Peters wrote:
> 4. Define an __eq__ method, which returns False if its arguments
> are non-comparable.
Looking at the SourceForge page, I think this is addressed by Bug
#887290:
https://sourceforge.net/tracker/index.php?func=detail&aid=887290&group_i
d=63070&atid=502756
I don't have 'diff' on this machine, and am *totally* swamped, but
here's the new code I ended up with:
def __eq__(self, other):
if isinstance(other, FixedPoint):
xn, yn, p = _norm(self, other, FixedPoint=type(self))
return not(cmp(xn, yn))
else:
return False
def __ne__(self, other):
if isinstance(other, FixedPoint):
xn, yn, p = _norm(self, other, FixedPoint=type(self))
return cmp(xn, yn)
else:
return True
...am I right in thinking that the presence of __eq__ and __ne__ doesn't
*harm* the class under older versions of Python?
Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org
More information about the Python-list
mailing list