如何在python 2.7中回溯函数?

mim*_*ock 4 python debugging python-2.7

我有一个大的python脚本,有多个文件,我需要知道调用方法的位置.在python中是否有回溯函数,如php中的debug_backtrace?

geo*_*org 8

请参阅回溯模块.

import traceback

def foo():
    bar()

def bar():
    baz()

def baz():
    traceback.print_stack() 
    # or trace = traceback.extract_stack()

foo()
Run Code Online (Sandbox Code Playgroud)