Try:
1/0
except exception,e:
print E
The output is an integer division or modulo by zero, only to know that the error is reported, but do not know in which file which function which line of the error. Use the Traceback module below
Import traceback
try:
1/0
except exception,e:
Traceback.print_exc ()
The output result is traceback (most recent call last): File "test_traceback.py", line 3, in <module> 1/0 Zerodivisionerror:intege R division or modulo by zero is very intuitive and facilitates debugging.
What is the difference between traceback.print_exc () and Traceback.format_exc ()? Format_exc () returns the string, Print_exc () is printed directly. That is, Traceback.print_exc () is the same as the print traceback.format_exc () effect. The Print_exc () can also accept the file parameter to be written directly to one of the files. For example, Traceback.print_exc (File=open (' tb.txt ', ' w+ ')) is written to the Tb.txt file.