Here are some options for how to inspect and debug Python code:
print
Add print
statements to your code and rerun your program to view the output:
print('any', values, you_want, 'to see')
Python REPL
Instead of running your whole program, start a Python REPL session, and import and run just the portions of your code you want to inspect:
$ python
$ from my_module import my_function
$ my_function()
pdb
See my Pdb notes.
ipdb
- gotcha/ipdb • IPython-enabled pdb 🛠️
- Debugging with ipdb - the normal way • Muhammad Osama Arshad 📺
- Debugging with ipdb - the better way • Muhammad Osama Arshad 📺
- Debugging “pytest” tests with “ipdb” debug mode • Michael Mintz 📺
# use ipdb instead of pdb
$ PYTHONBREAKPOINT=ipdb.set_trace python file.py
pudb
- …
# use pudb instead of pdb
$ PYTHONBREAKPOINT=pudb.set_trace python file.py
pdbpp
- pdbpp/pdbpp: pdb++ • A drop-in replacement for
pdb
🛠️
ipython
- IPython Documentation • IPython docs 📚
- 5 Ways of Debugging with IPython • Piotr Świtowski 📖
jupyter
See my Jupyter notes.
VS Code debugger
Research 📚
- Python Debug Cheatsheet • Peter Xie 📖
- Debugging Python Like a Boss • Zapier 📖
Inbox
- Online Python Tutor • Online Compiler and Visual Debugger for Python, Java, C, C++, and JavaScript 🛠️
- snoop • A powerful set of Python debugging tools, based on PySnooper 🛠️
- birdseye • Graphical Python debugger which lets you easily view the values of all evaluated expressions 🛠️
- Python Debugging (PyCharm + VS Code) - How to use the PyCharm and VS Code debuggers, and how to use breakpoints and conditional breakpoints to track down where problems are coming from - mCoding