Simpler way to put PDB breakpoints in Python code?

后端 未结 14 2240
不知归路
不知归路 2020-11-30 18:21

Just a convenience question. I\'ve been a bit spoiled with debuggers in IDEs like Visual Studio and XCode. I find it a bit clumsy to have to type import pdb; pdb.set_t

14条回答
  •  悲哀的现实
    2020-11-30 18:44

    If you don't want to manually set breakpoints every time running the program (in Python 3.2+), e.g. say you want to directly create a breakpoint at line 3 and stop the execution there:

    python -m pdb -c "b 3" -c c your_script.py

    The following information may help:

    If a file .pdbrc exists in the user’s home directory or in the current directory, it is read in and executed as if it had been typed at the debugger prompt. This is particularly useful for aliases. If both files exist, the one in the home directory is read first and aliases defined there can be overridden by the local file.

    Changed in version 3.2: .pdbrc can now contain commands that continue debugging, such as continue or next. Previously, these commands had no effect.

    New in version 3.2: pdb.py now accepts a -c option that executes commands as if given in a .pdbrc file, see Debugger Commands.

    • Source: https://docs.python.org/3.2/library/pdb.html

提交回复
热议问题