缘来路过 发表于 2017-5-1 11:33:30

python try语句如何打印错误行

     
python try语句如何打印错误行

打印当前.py文件错误行:
import sys
try:
        a =
        print a
except:
        s=sys.exc_info()
        print "Error '%s' happened on line %d" % (s,s.tb_lineno)
打印execfile的打印错误行:
try:
        execfile("tprint.py")
except Exception, info:
        #print info
        print "Error '%s' happened on line %d" % (info, info)
利用反射机制,调用函数,打印被调用方的错误行及错误信息        
try:
        callfunc.callfunc(myklass,strmethod,params)
except :
        print '=== STEP ERROR INFO START'
        import traceback
        traceback.print_exc()
        print '=== STEP ERROR INFO END'
页: [1]
查看完整版本: python try语句如何打印错误行