Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

See current frame without an error

Tags:

python

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.

like image 750
Colin Avatar asked Feb 22 '26 05:02

Colin


1 Answers

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().


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!