By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,096 Members | 1,568 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,096 IT Pros & Developers. It's quick & easy.

Strange sorting error message

P: n/a
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.

Oct 3 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
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?

Diez

Oct 3 '06 #2

P: n/a

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.

Oct 3 '06 #3

P: n/a
Dustan wrote:
I'm hiding some of the details here, because I don't want to say what
I'm actually doing.
[...]
I have the answer to your problem but I don't actually want to tell you
what it is.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Oct 4 '06 #4

P: n/a

Steve Holden wrote:
Dustan wrote:
I'm hiding some of the details here, because I don't want to say what
I'm actually doing.
[...]

I have the answer to your problem but I don't actually want to tell you
what it is.
That's great, seeing as I already figured out the answer, as I have
already posted in a reply.

Are you saying I broke one of these rules?
http://www.catb.org/~esr/faqs/smart-questions.html
Or are you just being plain rude?
A lack of a response from you implies the latter...
>
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
Oct 5 '06 #5

P: n/a
On 2006-10-05, Dustan <Du**********@gmail.comwrote:
>
Steve Holden wrote:
>Dustan wrote:
I'm hiding some of the details here, because I don't want to
say what I'm actually doing.
[...]

I have the answer to your problem but I don't actually want to
tell you what it is.

That's great, seeing as I already figured out the answer, as I
have already posted in a reply.
I had a good laugh at it.
Are you saying I broke one of these rules?
http://www.catb.org/~esr/faqs/smart-questions.html
Or are you just being plain rude?
A lack of a response from you implies the latter...
SPOILER SPACE

It was a joke, based on you hiding what you are doing, he decided
to hide the solution to your problem. Get it?

--
Neil Cerutti
Oct 5 '06 #6

P: n/a

Neil Cerutti wrote:
On 2006-10-05, Dustan <Du**********@gmail.comwrote:

Steve Holden wrote:
Dustan wrote:
I'm hiding some of the details here, because I don't want to
say what I'm actually doing.
[...]

I have the answer to your problem but I don't actually want to
tell you what it is.
That's great, seeing as I already figured out the answer, as I
have already posted in a reply.

I had a good laugh at it.
Are you saying I broke one of these rules?
http://www.catb.org/~esr/faqs/smart-questions.html
Or are you just being plain rude?
A lack of a response from you implies the latter...

SPOILER SPACE

It was a joke, based on you hiding what you are doing, he decided
to hide the solution to your problem. Get it?
Ah, now I get it... Well, not really. I'm not outgoing, so it's hard
for me to spot a joke when I see one.
>
--
Neil Cerutti
Oct 5 '06 #7

P: n/a
Dustan wrote:
Neil Cerutti wrote:
>>On 2006-10-05, Dustan <Du**********@gmail.comwrote:
>>>Steve Holden wrote:

Dustan wrote:

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

I have the answer to your problem but I don't actually want to
tell you what it is.

That's great, seeing as I already figured out the answer, as I
have already posted in a reply.

I had a good laugh at it.

>>>Are you saying I broke one of these rules?
http://www.catb.org/~esr/faqs/smart-questions.html
Or are you just being plain rude?
A lack of a response from you implies the latter...

SPOILER SPACE

It was a joke, based on you hiding what you are doing, he decided
to hide the solution to your problem. Get it?


Ah, now I get it... Well, not really. I'm not outgoing, so it's hard
for me to spot a joke when I see one.
Even when it smacks you in the face, apparently. Anyway, I'm sorry if
you thought I was getting at you in any way. Just trying to amuse the
group ...

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Oct 6 '06 #8

P: n/a
Steve Holden wrote:
Even when it smacks you in the face, apparently. Anyway, I'm sorry if
you thought I was getting at you in any way. Just trying to amuse the
group ...
time to reinstate mandatory use of the <winktag ?

</F>

Oct 6 '06 #9

P: n/a
On 10/5/06, Neil Cerutti <ho*****@yahoo.comwrote:
It was a joke, based on you hiding what you are doing, he decided
to hide the solution to your problem. Get it?
What if it was for a proprietary software of some kind?

-- Theerasak
Oct 6 '06 #10

P: n/a
On 2006-10-06, hanumizzle <ha********@gmail.comwrote:
On 10/5/06, Neil Cerutti <ho*****@yahoo.comwrote:
>It was a joke, based on you hiding what you are doing, he decided
to hide the solution to your problem. Get it?

What if it was for a proprietary software of some kind?
It wasn't sufficiently clear, hence the mild ribbing.

--
Neil Cerutti
The Rev. Merriwether spoke briefly, much to the delight of the
audience. --Church Bulletin Blooper
Oct 6 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.