Python 3 __cmp__语义变化? [英] Python 3 __cmp__ semantic change?
问题描述
Hello group,
我正在将一些我的代码移植到Python 3.一个类有__cmp__
运算符重载,但是比较没有这似乎不再适用了:
Traceback(最近一次调用最后一次):
文件" ./ parse",第25行,in < module>
print(x< y)
TypeError:unorderable类型:IP()< IP()
是否有某种语义变化?
亲切的问候,
Johannes >
-
" Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verl?sterung von Gott,Bibel und mir und bewusster Blasphemie。
- Prophet und Vision?r Hans Joss又名HJP in de.sci.physik
< 48 ********** ************@news.sunrise.ch>
Hello group,
I''m porting some code of mine to Python 3. One class has the __cmp__
operator overloaded, but comparison doesn''t seem to work anymore with that:
Traceback (most recent call last):
File "./parse", line 25, in <module>
print(x < y)
TypeError: unorderable types: IP() < IP()
Was there some kind of semantic change?
Kind regards,
Johannes
--
"Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verl?sterung von Gott, Bibel und mir und bewusster Blasphemie."
-- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik
<48**********************@news.sunrise.ch>
推荐答案
11月20日,1:18 * pm, Johannes Bauer< dfnsonfsdu ... @ gmx.dewrote:
On Nov 20, 1:18*pm, Johannes Bauer <dfnsonfsdu...@gmx.dewrote:
Hello group,
我正在搬运一些我的代码是Python 3.一个类有__cmp__
运算符重载,但比较似乎不再适用于:
Traceback(最近的电话最后一次):
*文件" ./ parse",第25行,在< module>
* * print(x< y)
TypeError:unorderable类型:IP()< IP()
是否存在某种语义变化?
Hello group,
I''m porting some code of mine to Python 3. One class has the __cmp__
operator overloaded, but comparison doesn''t seem to work anymore with that:
Traceback (most recent call last):
* File "./parse", line 25, in <module>
* * print(x < y)
TypeError: unorderable types: IP() < IP()
Was there some kind of semantic change?
重载__lt__方法。
Inyeol
Overload __lt__ method.
Inyeol
在******** @ gmail.com schrieb:
In********@gmail.com schrieb:
11月20日下午1:18,Johannes Bauer< dfnsonfsdu ... @ gmx.dewrote:
On Nov 20, 1:18 pm, Johannes Bauer <dfnsonfsdu...@gmx.dewrote:
> Hello group,
我正在将一些我的代码移植到Python 3.一个类有__cmp__
运算符重载,但比较似乎不再适用于:
文件" ./ parse",第25行,在< module>
print(x< y)
TypeError:unorderable类型: IP()< IP()
是否存在某种语义变化?
>Hello group,
I''m porting some code of mine to Python 3. One class has the __cmp__
operator overloaded, but comparison doesn''t seem to work anymore with that:
Traceback (most recent call last):
File "./parse", line 25, in <module>
print(x < y)
TypeError: unorderable types: IP() < IP()
Was there some kind of semantic change?
重载__lt__方法。
Overload __lt__ method.
好吧,当然我可以这样做,但是python doc说:
通过比较操作调用丰富的比较(见上文)不是定义的
。
http://www.python.org/doc/2.5.2/ref/customization.html
和我的代码工作正常2.5 - 仅在3.0上它不再工作
了。为什么?
问候,
约翰内斯
-
" ; Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verl?sterung von Gott,Bibel und mir und bewusster Blasphemie。
- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik
< 48 ********************** @ news.sunrise.ch>
Well, of course I could do that, but the python doc says:
"Called by comparison operations if rich comparison (see above) is not
defined."
http://www.python.org/doc/2.5.2/ref/customization.html
And my code works just fine with 2.5 - only on 3.0 it doesn''t work
anymore. Why is that?
Regards,
Johannes
--
"Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verl?sterung von Gott, Bibel und mir und bewusster Blasphemie."
-- Prophet und Vision?r Hans Joss aka HJP in de.sci.physik
<48**********************@news.sunrise.ch>
Johannes Bauer写道:
Johannes Bauer wrote:
Hello group,
I我将我的一些代码移植到Python 3.一个类有__cmp__
运算符重载,但比较似乎不再适用于:
Hello group,
I''m porting some code of mine to Python 3. One class has the __cmp__
operator overloaded, but comparison doesn''t seem to work anymore with that:
__cmp__消失了
Christian
__cmp__ is gone
Christian
这篇关于Python 3 __cmp__语义变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!