How to step through Python code to help debug issues?

前端 未结 14 873
梦如初夏
梦如初夏 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:34

    PyCharm is an IDE for Python that includes a debugger. Watch this YouTube video for an introduction on using PyCharm's debugger to step through code.

    PyCharm Tutorial - Debug python code using PyCharm

    Note: This is not intended to be an endorsement or review. PyCharm is a commercial product that one needs to pay for, but the company does provide a free license to students and teachers, as well as a "lightweight" Community version that is free and open-source.

    0 讨论(0)
  • 2020-11-22 11:36

    If you come from Java/C# background I guess your best bet would be to use Eclipse with Pydev. This gives you a fully functional IDE with debugger built in. I use it with django as well.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-11-22 11:42

    https://wiki.python.org/moin/PythonDebuggingTools

    pudb is a good drop-in replacement for pdb

    0 讨论(0)
  • 2020-11-22 11:43

    If you want an IDE with integrated debugger, try PyScripter.

    0 讨论(0)
  • 2020-11-22 11:49

    Programmatically stepping and tracing through python code is possible too (and its easy!). Look at the sys.settrace() documentation for more details. Also here is a tutorial to get you started.

    0 讨论(0)
提交回复
热议问题