title: Comparing class instances in python
body: <p>I built a new class in python which defines time with 6 figures (such as 18:45:00)</p>
  
  <pre><code>class Time(object):
  
      def __init__(self, hour, minute, second):
          minute = minute + second / 60
          hour = hour + minute / 60        
          self.hour = hour % 24
          self.minute = minute % 60
          self.second = second  % 60
  </code></pre>
  
  <p>I have also defined many methods to make it work as it should.
  the problem I have is with the cmp method:</p>
  
  <pre><code>def __cmp__(self,other):
      return cmp(self.to_seconds(),other.to_seconds())
  </code></pre>
  
  <p>It works fine when I try to compare times, if I'm sorting a list of times it also works fine. But if I'm trying to sort a list of times and integers or strings it also work.
  How can I define it to compare only times and to raise and error if trying to compare time with something that isn't.</p>