Python can be debugged without changing code

Debugging python code seems to be a trivial task, just paste the following lines to start the debugger.

import pdb


Yes, so I tried this and it works really well. It is a decent debugger.

But is it possible to run an unmodified python program, perhaps by specifying a text file, specifying breakpoints? This is how I usually do it in Java or Flash.


source to share

2 answers

Save the file with a name .pdbrc

in the same folder as your script file. Paste your control information into it:

b 3
b 5
b 70
b 89


Run your script in pdb like this:

python -m pdb


and pdb fetch and insert your breakpoints. Unfortunately, it won't save any changes you make to it while debugging.

Alternatively, you can specify them on the first line

(Pdb) b 3;;b 5;;b 70;;b 89




As the documentation explains , you can start it with:

python -m pdb




All Articles