奇怪的排序错误消息 [英] Strange sorting error message

查看:89
本文介绍了奇怪的排序错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里隐藏了一些细节,因为我不想说什么

我实际上在做什么。


我有一个特殊目的类,所有设置都是__cmp__方法,并且准备好进行排序。然后我有一个基于

内置类型列表的特殊类(虽然我实际上并没有继承列表;我可能应该使用
)。当我创建一个包含2个或更多项的实例,并且
尝试对其进行排序时,我收到以下奇怪的错误消息:

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()
>>myList.sort()



Traceback(大多数最近的电话最后一次):

文件"< console>",第1行,< module>

文件" [listModulePath]",第239行,排序

self.listOfObjects.sort()

TypeError:需要一个整数


排序方法''代码就是你所看到的;它是一种单行方法。


我唯一能想到的是__cmp__方法返回

不是整数的东西,它是不是。

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.

推荐答案

Dustan schrieb:
Dustan schrieb:

I我在这里隐藏了一些细节,因为我不想说什么是我实际上在做什么。
I''m hiding some of the details here, because I don''t want to say what
I''m actually doing.


我有一个特殊用途的类,所有设置都是__cmp__,并且

准备进行排序。然后我有一个基于

内置类型列表的特殊类(虽然我实际上并没有继承列表;我可能应该使用
)。当我创建一个包含2个或更多项的实例,并且
尝试对其进行排序时,我收到以下奇怪的错误消息:
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()
>>>myList.sort()



Traceback(最近一次调用最后一次):

文件"< console>",第1行,在< module>

文件" [listModulePath]",第239行,排序

self.listOfObjects.sort()

TypeError:需要一个整数


排序方法的代码就是你所看到的;它是一种单行方法。


我唯一能想到的是__cmp__方法返回

不是整数的东西,它是不是。

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.



将对象填入标准列表并对它们进行排序是否有效?

的方法如何?_ />

Diez

Does stuffing the objects in a standard list and sorting them work? How
does the __cmp__-method look like?

Diez




Diez B. Roggisch写道:

Diez B. Roggisch wrote:

Dustan schrieb:
Dustan schrieb:

I'我在这里隐藏了一些细节,因为我不想说什么

我实际上在做什么。
I''m hiding some of the details here, because I don''t want to say what
I''m actually doing.


我有一个特殊用途的类,所有设置都是__cmp__,并且

准备进行排序。然后我有一个基于

内置类型列表的特殊类(虽然我实际上并没有继承列表;我可能应该使用
)。当我创建一个包含2个或更多项目的实例,并且

尝试对其进行排序时,我收到以下奇怪的错误消息:
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()
>>myList.sort()



Traceback(最近一次调用最后一次):

文件"< console>",line 1,在< module>

文件" [listModulePath]",第239行,排序

self.listOfObjects.sort()

TypeError:需要一个整数


排序方法的代码就是你所看到的;它是一种单行方法。


我唯一能想到的是__cmp__方法返回

不是整数的东西,它是不是。

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.



将对象填入标准列表并对其进行排序是否有效?

如何看待__cmp __-方法?


Does stuffing the objects in a standard list and sorting them work? How
does the __cmp__-method look like?



哎呀,我在__cmp__中创建了变量returnValue,但是

忘了返回它。现在它有效。


这是一个愚蠢的错误;抱歉,麻烦。

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.


Dustan写道:
Dustan wrote:

我隐藏了一些这里的细节,因为我不想说什么

我实际上在做什么。

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



我有你的问题的答案,但我真的不想告诉你

它是什么。


问候

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

最近的Ramblings http://del.icio.us/steve.holden

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


这篇关于奇怪的排序错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆