Diez B. Roggisch wrote: > Dustan schrieb: > > 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. > > Does stuffing the objects in a standard list and sorting them work? How > does the __cmp__-method look like?
Whoops, I had created the variable returnValue in __cmp__, but forgotten to return it. Now it works. That was a dumb mistake; sorry for the trouble. -- http://mail.python.org/mailman/listinfo/python-list