我在python中使用try except block,而try块失败,如何打印有意义的错误消息。我正在寻找像C
中的perror()之类的东西答案 0 :(得分:6)
>>> try:
... 0/0
... except Exception,e:
... print e.message
...
integer division or modulo by zero
或在Python 2.6及更高版本中,e.args
,因为BaseException.message has been deprecated
>>> try:
... 0/0
... except Exception,e:
... print e.args
...
('integer division or modulo by zero',)
答案 1 :(得分:-2)
try:
pass
except Exception, err:
print err