Reputation: 31
In Python, is there a way to see the current stack frame? That is, I want to see a list of files which were called to get to my current location.
Essentially, I want to see
try:
1/0
except:
traceback.print_exc()
without actually raising an error.
Upvotes: 3
Views: 120
Reputation:
You want a stack trace, not a stack frame (the stack frame is one area in the stack holding e.g. the local variables of the current function). The traceback module has various means to get a stack trace without raising an exception. To print a stack trace directly, use traceback.print_stack()
.
Upvotes: 2
Reputation: 9945
You could use pdb and to add a breakpoint.
import pdb; pdb.set_trace()
Then user the where command to tell you where you are in the stack frame.
Upvotes: 0