How can you programmatically inspect the stack trace of an exception in Python?

前端 未结 5 1377
一个人的身影
一个人的身影 2021-02-02 12:19

When an exception occurs in Python, can you inspect the stack? Can you determine its depth? I\'ve looked at the traceback module, but I can\'t figure out how to use it.

<
5条回答
  •  北海茫月
    2021-02-02 13:18

    You can use the inspect module which has some utility functions for tracing. Have a look at the overview of properties of the frame objects.

提交回复
热议问题