fixedpoint cmp conundrum

Robert Brewer fumanchu at amor.org
Mon May 3 19:22:53 EDT 2004


Consider the following:

PythonWin 2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)]
on win32.
Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) -
see 'Help/About PythonWin' for further copyright information.
>>> import fixedpoint
>>> a = fixedpoint.FixedPoint(3, 2)
>>> bunch = [None, 12, a]
>>> bunch.index(None)
0
>>> bunch.index(12)
1
>>> bunch.index(27)
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
ValueError: list.index(x): x not in list

...so far, this is normal and expected.


>>> bunch.index(a)
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "C:\Python23\Lib\fixedpoint.py", line 316, in __cmp__
    xn, yn, p = _norm(self, other, FixedPoint=type(self))
  File "C:\Python23\Lib\fixedpoint.py", line 482, in _norm
    y = FixedPoint(y, x.p)
  File "C:\Python23\Lib\fixedpoint.py", line 255, in __init__
    raise TypeError("can't convert to FixedPoint: " + `value`)
TypeError: can't convert to FixedPoint: None


Mmrph! I could fix this by:

1. Iterating through "bunch" by hand and trapping TypeError,
2. Overriding or hacking the __cmp__ function in fixedpoint, or
3. Overriding or hacking the _norm function in fixedpoint

The question is: given that there are multiple places to "fix" this,
where should I do so?


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org




More information about the Python-list mailing list