Go Back   Velocity Reviews > Newsgroups > Python
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Python - TypeErrors

 
Thread Tools Search this Thread
Old 02-28-2009, 08:07 PM   #1
Default TypeErrors


Sean Novick <> wrote:
> First lookup:
> Traceback (most recent call last):
> File "F:\CSC113 Module 4 CA\sample database.py", line 72, in <module>
> class phonedb:
> File "F:\CSC113 Module 4 CA\sample database.py", line 146, in phonedb
> for entry in foo.lookup('reifsch'):
> File "F:\CSC113 Module 4 CA\sample database.py", 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).

--RDM



rdmurray@bitdance.com
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46