Equivalent perror function in python

I use try other than a block in python, while a try block does not work, how to print a meaningful error message. I am looking for something like perror () in C

+3
source share
2 answers
>>> try:
...     0/0
... except Exception,e:
...     print e.message
...
integer division or modulo by zero

or in Python 2.6 and higher e.args, due toBaseException.message has been deprecated

>>> try:
...     0/0
... except Exception,e:
...     print e.args
...
('integer division or modulo by zero',)
+5
source
try:
   pass
except Exception, err:
   print err
-2
source

Source: https://habr.com/ru/post/1731829/


All Articles