how to compare two objects in class using __cmp__ method in Python?
<pre><code>class Box(object):
def __init__(self, ival):
    self.value = ival
def __cmp__(self,other):
    if self.value &lt; other:
        return 
    elif self.value &gt; other:
        return 1
    else:return 0
</code></pre>

<p>But when I wanna test the program with :</p>

<pre><code>Box(2) &lt; Box(2)
Box(2) &lt;= Box(2)
Box(1) &gt;= Box(2)
Box(3) &gt; Box(2)
Box(0) == Box(1)
Box(0) != Box(0)
</code></pre>

<p>Part of the code below:</p>

<pre><code>Box(1) &gt;= Box(2)
Box(3) &gt; Box(2)
Box(0) == Box(1)
</code></pre>

<p>has shown </p>

<blockquote>
  <p>TypeError: an integer is required</p>
</blockquote>

<p>Anyone knows why?</p>

<p>EDITED :I added the -1 before but somehow I deleted it -.-
sorry for asking such careless question!</p>

<p><a href="https://docs.python.org/2/library/functions.html#cmp" rel="nofollow">Doc reference</a> on <code>__cmp__</code>:</p>

<blockquote>
  <p>Should <em>return</em> a <strong>negative integer</strong> if <code>self &lt; other</code>, <strong>zero</strong> if <code>self == other</code>, a <strong>positive integer</strong> if <code>self &gt; other</code></p>
</blockquote>

<p>So all your branches should return an integer but the <code>if</code> branch is returning <code>None</code>.</p>

python python-2.7