How to step through Python code to help debug issues?

前端 未结 14 1104
梦如初夏
梦如初夏 2020-11-22 11:17

In Java/C# you can easily step through code to trace what might be going wrong, and IDE\'s make this process very user friendly.

Can you trace through python code in

14条回答
  •  借酒劲吻你
    2020-11-22 11:39

    Starting in Python 3.7, you can use the breakpoint() built-in function to enter the debugger:

    foo()
    breakpoint()  # drop into the debugger at this point
    bar()
    

    By default, breakpoint() will import pdb and call pdb.set_trace(). However, you can control debugging behavior via sys.breakpointhook() and use of the environment variable PYTHONBREAKPOINT.

    See PEP 553 for more information.

提交回复
热议问题