In Java/C# you can easily step through code to trace what might be going wrong, and IDE\'s make this process very user friendly.
Can you trace through python code in
ipdb adds IPython functionality to pdb, offering the following HUGE improvements:
Much like pdg, ipdb is still far from perfect and completely rudimentary if compared to GDB, but it is already a huge improvement over pdb.
Usage is analogous to pdb
, just install it with:
python3 -m pip install --user ipdb
and then add to the line you want to step debug from:
__import__('ipdb').set_trace(context=21)
You likely want to add a shortcut for that from your editor, e.g. for Vim snipmate I have:
snippet ipd
__import__('ipdb').set_trace(context=21)
so I can type just ipd
and it expands to the breakpoint. Then removing it is easy with dd
since everything is contained in a single line.
context=21
increases the number of context lines as explained at: How can I make ipdb show more lines of context while debugging?
Alternatively, you can also debug programs from the start with:
ipdb3 main.py
but you generally don't want to do that because:
Or alternatively, as in raw pdb 3.2+ you can set some breakpoints from the command line:
ipdb3 -c 'b 12' -c 'b myfunc' ~/test/a.py
although -c c
is broken for some reason: https://github.com/gotcha/ipdb/issues/156
python -m module
debugging has been asked at: How to debug a Python module run with python -m from the command line? and since Python 3.7 can be done with:
python -m pdb -m my_module
Serious missing features of both pdb and ipdb compared to GDB:
ipdb specific annoyances:
Tested in Ubuntu 16.04, ipdb==0.11, Python 3.5.2.