Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > TypeErrors

Thread Tools

Posts: n/a
Sean Novick <(E-Mail Removed)> wrote:
> First lookup:
> Traceback (most recent call last):
> File "F:\CSC113 Module 4 CA\sample", line 72, in <module>
> class phonedb:
> File "F:\CSC113 Module 4 CA\sample", line 146, in phonedb
> for entry in foo.lookup('reifsch'):
> File "F:\CSC113 Module 4 CA\sample", line 101, in lookup
> if cmp(e, string) =3D=3D 0:
> TypeError: comparison did not return an int
> I do not know what this error means. I tried to look it up in help, but to no
> avail. If someone could please help or tell me where I could find an answer.
> Thanks.

The 'cmp' function (which is depricated, by the way) asks the two
arguments to compare themselves. It does this by invoking the __cmp__
method on the first object, passing it the second. (Actually it's more
complicated than that, but it will do as a partial explanation for now).
The __cmp__ method is expected to return an integer, which represents
the results of doing the comparison (see the docs if you want to know
the values...but as I said cmp and __cmp__ a depricated).

So, whatever 'e' is (and we can't tell from the traceback, you'll have
to work through your code to figure it out, probably by sprinkling in
'print' statements), its __cmp__ method didn't return an integer.

When you fix this, I would recommend converting to using rich comparisons
(__eq__, __lt__), etc, since __cmp__ is eventually going away (it doesn't
exist in Python 3.x).


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off