擅长:python、mysql、java
<p>如果我对你的问题理解正确,你需要这样的东西:</p>
<pre><code>>>> class A(int):
... def __cmp__(self, other):
... return super(A, self).__cmp__(A(other)) # < - A(other) instead of other
...
>>> a = str('5')
>>> b = A(5)
>>> a == b
True
</code></pre>
<p><strong>更新</strong></p>
<p>关于2.x cpython源代码,您可以在函数<code>wrap_cmpfunc</code>中找到这个结果的原因,该函数实际上检查了两件事情:给定的比较函数是<code>func</code>,而{<cd4>}是{<cd5>}的子类型。在</p>
^{pr2}$