How to debug Python scripts and API code in the console and in VS Code
Learn different ways to debug your Python code
Debugging is an important step in Python programming, whether you are a Python data scientist or software developer. It can be fairly straightforward to debug simple Python scripts. However, it is more advanced to debug Python API code, especially with VS Code. In this article, the most common ways to debug Python scripts and API code are introduced, both in the console and in VS Code. You shall then be fairly clear about which tools to use and how to use them in your practical work.
How to debug Python scripts with pdb in the console?
In the repo cloned, there is a simple script called python_script.py
, where the command line arguments are simply echoed:
To debug a script, the most “naive” way is to use print
wherever necessary. This, however, is not convenient. A much better way is to use the pdb module. pdb is the built-in Python debugger that can be used to debug Python programs interactively.