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'