fixedpoint cmp conundrum

Discussion in 'Python' started by Robert Brewer, May 4, 2004.

  1. 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 () -
    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
    Robert Brewer, May 4, 2004
    #1
    1. Advertising

  2. Robert Brewer

    Aahz Guest

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

    In article <>,
    Robert Brewer <> wrote:
    >
    >>>> 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.
    --
    Aahz () <*> http://www.pythoncraft.com/

    Adopt A Process -- stop killing all your children!
    Aahz, May 4, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Owen

    Clunky Cache Code Conundrum?

    Jim Owen, Jul 3, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    354
    dave wanta
    Jul 3, 2003
  2. Iain
    Replies:
    0
    Views:
    351
  3. Andrea Sansottera

    no cmp field defined in cmp ejb

    Andrea Sansottera, Jul 16, 2004, in forum: Java
    Replies:
    0
    Views:
    371
    Andrea Sansottera
    Jul 16, 2004
  4. Sibylle Koczian
    Replies:
    4
    Views:
    518
    Sibylle Koczian
    Jan 25, 2005
  5. jelle
    Replies:
    7
    Views:
    398
    Terry Reedy
    Feb 2, 2005
Loading...

Share This Page