Debugging Python programs that require CLI arguments in VSCode
Command Palette (CTRL+SHIFT+P): Debug: Add Configuration
Then, select “Python Debugger”
Then, select “Python File with Arguments”
VSCode then creates the .vscode
directory in your project, if it doesn’t exist already, and adds launch.json
as follows:
{
// 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": "${file}",
"console": "integratedTerminal",
"args": "${command:pickArgs}"
}
]
}
If you don’t change anything, when you debug a file VSCode will prompt you for arguments to pass the file every time you run the debugger.
Can also click, bottom right, “Add Configuration” which will stub out adding more configs in the JSON so that you can tailor it to your specific application. For example:
{
// 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": "Blue Horseshoe Debugger",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": ["run",
"--players", "5",
"--duration", "2",
"--round-end", "fixed",
"--config", "strategy_config.yaml",
"--simulation", "true",
"--strategies", "conservative,conservative,conservative,momentum,arbitrage"]
},
{
"name": "Python Debugger: Current File with Arguments",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": "${command:pickArgs}"
}
]
}