Catching an exception that would print like this:
Traceback (most recent call last):
File "c:/tmp.py", line 1, in <module>
4 / 0
ZeroDivisionError: integer division or modulo by zero
I want to format it into:
ZeroDivisonError, tmp.py, 1
Catching an exception that would print like this:
Traceback (most recent call last):
File "c:/tmp.py", line 1, in <module>
4 / 0
ZeroDivisionError: integer division or modulo by zero
I want to format it into:
ZeroDivisonError, tmp.py, 1
import sys, os
try:
raise NotImplementedError("No error")
except Exception, e:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, tb.tb_lineno)
try:
bla
except Exception, e:
import traceback, os.path
top = traceback.extract_stack()[-1]
print ", ".join([type(e).__name__, os.path.basename(top[0]), str(top[1])])