How to step through Python code to help debug issues?

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

    Let's take look at what breakpoint() can do for you in 3.7+.

    I have installed ipdb and pdbpp, which are both enhanced debuggers, via

    pip install pdbpp
    pip install ipdb
    

    My test script, really doesn't do much, just calls breakpoint().

    #test_188_breakpoint.py
    myvars=dict(foo="bar")
    print("before breakpoint()")
    breakpoint()   #                                                                     
    0 讨论(0)
  • 2020-11-22 11:52

    There is a module called 'pdb' in python. At the top of your python script you do

    import pdb
    pdb.set_trace()
    

    and you will enter into debugging mode. You can use 's' to step, 'n' to follow next line similar to what you would do with 'gdb' debugger.

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