See current frame without an error
In Python, is there a way to see the current stack frame? Tha开发者_运维百科t 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.
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()
.
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.
精彩评论