Step-by-step debugging with IPython

后端 未结 15 2211
隐瞒了意图╮
隐瞒了意图╮ 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 03:55

    Developing New Code

    Debugging inside IPython

    1. Use Jupyter/IPython cell execution to speed up experiment iterations
    2. Use %%debug for step through

    Cell Example:

    %%debug
    ...: for n in range(4):
    ...:    n>2
    

    Debugging Existing Code

    IPython inside debugging

    1. Debugging a broken unit test: pytest ... --pdbcls=IPython.terminal.debugger:TerminalPdb --pdb
    2. Debugging outside of test case: breakpoint(), python -m ipdb, etc.
    3. IPython.embed() for full IPython functionality where needed while in the debugger

    Thoughts on Python

    I agree with the OP that many things MATLAB does nicely Python still does not have and really should since just about everything in the language favors development speed over production speed. Maybe someday I will contribute more than trivial bug fixes to CPython.

    https://github.com/ipython/ipython/commit/f042f3fea7560afcb518a1940daa46a72fbcfa68

    See also Is it possible to run commands in IPython with debugging?

提交回复
热议问题