fixedpoint cmp conundrum
Robert Brewer
fumanchu at amor.org
Tue May 4 00:16:13 EDT 2004
I described a problem about list.index() and fixedpoint:
> > >>> import fixedpoint
> > >>> 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?
and Tim himself replied:
> 4. Define an __eq__ method, which returns False if its arguments
> are non-comparable.
...to which I can only say:
Thanks! :) Nailed it.
Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org
More information about the Python-list
mailing list