fixedpoint cmp conundrum

R

Robert Brewer

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 ([email protected]) -
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.

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
(e-mail address removed)
 
A

Aahz

[BTW, please try to avoid using quoted-printable if at all possible]

a = fixedpoint.FixedPoint(3, 2)
bunch = [None, 12, a]
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?

http://fixedpoint.sourceforge.net/
with a patch using option 2.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top