How to get the last exception object after an error is raised at a Python prompt?

后端 未结 2 1989
半阙折子戏
半阙折子戏 2020-12-14 14:46

When debugging Python code at the interactive prompt (REPL), often I\'ll write some code which raises an exception, but I haven\'t wrapped it in a try/exc

2条回答
  •  攒了一身酷
    2020-12-14 14:56

    The sys module provides some functions for post-hoc examining of exceptions: sys.last_type, sys.last_value, and sys.last_traceback.

    sys.last_value is the one you're looking for.

提交回复
热议问题