How to return a function in python 2.7?

I have a large python script with several files, and I need to know where the method was called. Is there a backtrace function in python like debug_backtrace in php?

+3
source share
2 answers

See traceback module .

import traceback

def foo():
    bar()

def bar():
    baz()

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

foo()
+8
source

If you want to debug python

import pdb

then release

pdb.set_trace()

Where would you like to start debugging

see this site for more information

http://docs.python.org/library/pdb.html

+3
source

All Articles