import sys def pstack(depth = 0): frame = sys._getframe(depth) cnt = 0 while frame: print "###", cnt, frame.f_code.co_name, frame.f_code.co_filename, frame.f_lineno frame = frame.f_back cnt = cnt + 1 def test(): pstack(0) print "-"*20 pstack(1) if __name__ == "__main__": test()