I am new at Python and I'm stuck at this problem. I am trying to compare two "exception objects", example:
try:
0/0
except Exception as e:
print e
>> integer division or modulo by zero
try:
0/0
except Exception as e2:
print e2
>> integer division or modulo by zero
e == e2
>> False
e is e2
>> False
How should I perform this comparison to obtain a "True"?
What I am trying to do:
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)
(probably some syntax error)
Why I am doing that? Because I don't want to print the same error twice