我是Python的新手,我坚持这个问题.我试图比较两个"异常对象",例如:
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
Run Code Online (Sandbox Code Playgroud)
我应该如何进行这种比较以获得"真实"?
我想做什么:
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 …Run Code Online (Sandbox Code Playgroud)