在python錯誤調試過程中有時需要列印當前python檔案錯誤行,以下來介紹一下方法:
import sys
try:
a = [1,2]
a = [1,2]
s=sys.exc_info()
print "Error '%s' happened on line %d" % (s[1],s[2].tbtbno)
: execfile("tprint.py")except Exception, info: #print info[1] #print info[1]%/commcom info[ 1][1])
利用反射機制,呼叫函數,印出被呼叫方的錯誤行及錯誤訊息
try:
callfunc.callfunc(myklass,strklm. '= == STEP ERROR INFO START'
import traceback
traceback.print_exc()
traceback.print_exc()