Step-by-step debugging with IPython

后端 未结 15 2228
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 03:43

From what I have read, there are two ways to debug code in Python:

  • With a traditional debugger such as pdb or ipdb. This supports c

15条回答
  •  清歌不尽
    2020-12-02 04:01

    You can use IPython's %pdb magic. Just call %pdb in IPython and when an error occurs, you're automatically dropped to ipdb. While you don't have the stepping immediately, you're in ipdb afterwards.

    This makes debugging individual functions easy, as you can just load a file with %load and then run a function. You could force an error with an assert at the right position.

    %pdb is a line magic. Call it as %pdb on, %pdb 1, %pdb off or %pdb 0. If called without argument it works as a toggle.

提交回复
热议问题