-1

I have inherited a large Python project in which there are points whereI want to know how I got there. So I would like to see a stracetrace.

It seems that the traceback module can do that, but I need to throw an exception.
Is there a way to get a stacktrace without throwing an exception?

inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241

2 Answers2

3

traceback is one option:

import traceback

traceback.print_stack()
Nathaniel Mallet
  • 401
  • 2
  • 10
3

you want inspect.stack(), which returns a list of frame objects

import inspect

def a(): 
   b()

def b():
   c()

def c():
   print inspect.stack() 
theodox
  • 12,028
  • 3
  • 23
  • 36