import traceback
try:
1/0
except Exception,e:
traceback.print_exc()
The output is as follow:
Traceback (most recent call last):
File "test_traceback.py", line 3, in <module>
1/0
ZeroDivisionError: integer division or modulo by zero
However I don't want to use traceback.print_exc()
to print the output. Instead, I want to save the output to a variable. How can I do that?