python 跟踪 调试 trace
都在try cache后面使用
1. 普通方法
import sys, os, traceback, base64 errorMeg = '' for file, lineno, function, text in traceback.extract_tb(sys.exc_info()[2]): errorMeg += '%s\n%s, in %s\n%s: %s!' % (str(e), file, function, lineno, text) print "*" * 150 print errorMeg
2.系统方法
print "#"*50 import sys kkk = 15 f_back = sys._getframe() for i in range(kkk): f_back = getattr(f_back, "f_back",'end') if f_back=='end' or f_back is None: break #函数名,行数,文件名 myfo = sys._getframe(i) print myfo.f_code.co_name, myfo.f_lineno,myfo.f_code.co_filename