Debugging in Visual Studio Code — A Python app with arguments

Jonathan Henry
2 min readJun 25, 2024

--

A launch.json file is used to configure the debugger in Visual Studio Code.

Visual Studio Code generates a launch.json (under a .vscode folder in your project) with almost all of the required information. To get started with debugging, you need to fill in the program field with the path to the executable you plan to debug. This must be specified for both the launch and attach (if you plan to attach to a running instance at any point) configurations.

The generated file contains two sections, one that configures debugging for launch and a second that configures debugging for attach.

To create a launch.json file, click debug and run and click the textual link, create a launch.json file .

Run and Debug menu in Visual Studio Code
Run and Debug menu in Visual Studio Code

Select Python Debugger from the Command Palette. From the list of debug configurations that appear, select thePython file with arguments option. Copy and paste the below example, updating the programand args as necessary.

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File with Arguments",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/my_project/runner.py",
"console": "integratedTerminal",
"args": ["arg1", "arg2"]
}
]
}

To run your app with the newly saved configuration, click Run and Debug and click the play icon.

The play icon in Visual Studio Code in Run and Debug.
The play icon in Visual Studio Code in Run and Debug.

You should now be able to debug a Python app which takes arguments at runtime.

These short articles serve as short, useful tutorials, containing bitesize snippets of information I have learned as part of my coding journey, which might be useful to others.

--

--

Jonathan Henry

Senior software engineer with over 10-years industry experience. Side hustle: https://blakely.io