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
The simplest way to run the debugger on your script is just
pdb your_script.py
Running pdb on a Linux command-line gives
usage: pdb.py scriptfile [arg] ...
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.
I haven't tried it yet but they just implemented a new built-in called breakpoint() in Python 3.7 which means you can insert a breakpoint with one statement now:
breakpoint()
Easiest way to keep breakpoints, aliases and other settings saved across run is by using .pdbrc in the same folder as your script and then just run your script as python -m pdb <scriptname>.py
Enter commands just as you would do in pdb one per line. E.g.:
.\.pdbrc
--------
b 12
display var
c
In Atom if Python plugins installed, you can just type in 'pdb
' and hit enter and the snippet will type import and trace back for you.
I've used to this now that sometimes I just type it in even if I'm editing it in vim and waiting for the dropdown to appear.
You can run your program into pdb
from the command line by running
python -m pdb your_script.py
It will break on the 1st line, then you'll be able to add a breakpoint wherever you want in your code using the break
command, its syntax is:
b(reak) [[filename:]lineno | function[, condition]]
It is flexible enough to give you the ability to add a breakpoint anywhere.