I'm using try except block in python, while the try block fails , how to print meaningful error message. I'm looking for something like perror() in C
+1
A:
>>> try:
... 0/0
... except Exception,e:
... print e.message
...
integer division or modulo by zero
or in Python 2.6 and above, e.args
, because of BaseException.message has been deprecated
>>> try:
... 0/0
... except Exception,e:
... print e.args
...
('integer division or modulo by zero',)
S.Mark
2010-02-08 07:02:09
I'm using python 2.6 ,so e.args works fine.Thanks
lakshmipathi
2010-02-08 07:11:43