mimrock
mimrock

Reputation: 4883

How to backtrace a function in python 2.7?

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

Upvotes: 5

Views: 4780

Answers (2)

georg
georg

Reputation: 215039

See the traceback module.

import traceback

def foo():
    bar()

def bar():
    baz()

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

foo()

Upvotes: 9

dc5553
dc5553

Reputation: 1303

If you would like to debug python

import pdb

then drop a

pdb.set_trace()

Where ever you would like to start debugging

see this site for more information

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

Upvotes: 3

Related Questions