如何简单地打印Python的调用栈? __author__ = 'baixiao' def detailtrace(info): import sys import os retStr = "" curindex=0 f = sys._getframe() f = f.f_back # first frame is detailtrace, ignore it while hasattr(f, "f_code"): co = f.f_code retStr = "%s(%s:%s)->"%(os.path.basename(co.co_filename), co.co_name, f.f_lineno) + retStr f = f.f_back print retStr+info def func_b(): detailtrace("baixiao") def func_a(): func_b() if __name__ == "__main__": func_a()