Home > Backend Development > Python Tutorial > Print current python file error line

Print current python file error line

高洛峰
Release: 2016-10-19 14:56:20
Original
1563 people have browsed it

During the python error debugging process, it is sometimes necessary to print the error line of the current python file. Here is a method:

import sys

try:

a = [1,2]

print a[3]

except:

s=sys.exc_info()

print "Error '%s' happened on line %d" % (s[1],s[2].tb_lineno)

Print the error line of execfile:

try ; 1][1])

Use the reflection mechanism to call the function and print the callee’s error line and error message

try:

callfunc.callfunc(myklass,strmethod,params)

except :

print '= == STEP ERROR Info Start'

Import Traceback

Traceback.print_exc ()

Print '=== Step Error Info End'

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template