[Python]View plain copy 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. The following is an official reference document using the Traceback module https://docs.python.org/2/library/traceback.html
[python] view plain copy 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:in Teger 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.