Strange sorting error message

Dustan DustanGroups at gmail.com
Tue Oct 3 18:37:08 EDT 2006


I'm hiding some of the details here, because I don't want to say what
I'm actually doing.

I have a special-purpose class with a __cmp__ method all set up and
ready to go for sorting. Then I have a special class that is based on
the builtin type list (though I didn't actually inherit list; I
probably should). When I create an instance with 2 or more items, and
attempt to sort it, I get this strange error message:

>>> myList.sort()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "[listModulePath]", line 239, in sort
    self.listOfObjects.sort()
TypeError: an integer is required

The sort method's code is exactly what you see; it's a one-line method.

The only thing I can think of is the __cmp__ method is returning
something other than an integer, which it's not.




More information about the Python-list mailing list