unittest: Proposal to add failUnlessNear

Peter Otten __peter__ at web.de
Thu Jul 22 13:59:13 CEST 2004


[John Roth trying hard to confuse himself :-)]

Here's another perspective: abs(x) is ignorant of the class of x. Like
len(), it just calls the corresponding special method which does the
appropriate thing -- max(x, -x) for float, sqrt(x.real**2 + x.imag**2) for
complex -- or something theoretically equivalent, but better suited to the
limitations of numerical mathematics.

>>> class s(str):
...     def __abs__(self):
...             return self.upper()
...
>>> abs(s("so what"))
'SO WHAT'
>>>

Peter




More information about the Python-list mailing list