title: Comparing Exception Objects in Python
body: <p>I am new at Python and I'm stuck at this problem. I am trying to compare two "exception objects", example:</p>
  
  <pre><code>try:
      0/0
  except Exception as e:
      print e
  &gt;&gt; integer division or modulo by zero
  
  try:
      0/0
  except Exception as e2:
      print e2
  &gt;&gt; integer division or modulo by zero
  
  e == e2
  &gt;&gt; False
  
  e is e2
  &gt;&gt; False
  </code></pre>
  
  <p>How should I perform this comparison to obtain a "True"?</p>
  
  <p>What I am trying to do:</p>
  
  <pre><code>class foo():
      def bar(self, oldError = None):
          try:
              return urllib2.urlopen(someString).read()                   
          except urllib2.HTTPError as e:
              if e.code == 400: 
                 if e != oldError: print 'Error one'
              else: 
                 if e != oldError: print "Error two"
              raise
           except urllib2.URLError as e:
               if e != oldError: print 'Error three'
               raise
  
  class someclass():        
      # at some point this is called as a thread
      def ThreadLoop(self, stopThreadEvent):
          oldError = None
          while not stopThreadEvent.isSet():
              try:
                  a = foo().bar(oldError = oldError)
              except Exception as e:
                  oldError = e
              stopThreadEvent.wait(3.0)
  </code></pre>
  
  <p>(probably some syntax error)</p>
  
  <p>Why I am doing that?
  Because I don't want to print the same error twice</p>