Visual Studio Code: run Python file with arguments

Visual Studio Code only supports one launch.json file. However, it supports two or more configurations, and they appear in the left-hand menu/pane’s drop down list (instead of “No Configurations”).

Enter image description here

In the DEBUG pane, either click the Config button circled in red above or click the blue link “create launch.json file”:

Click it and it creates a launch.json file with debugging configurations. Edit this file and add the args in this key-pair format AND add multiple for different args including Variable Substitution!

{
    // 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: Current File with my args",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "args": [
                "--username", "Jeremy",
                "--account", "Stackoverflow"
            ],
            "console": "integratedTerminal"
        },
        {
            "name": "Python: Current File with UserName arg",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "args": ["${env:USERNAME}"],
            "console": "integratedTerminal"
        }
    ]
}

Put a breakpoint in your Python script, for example on the first line under def main(...) and then press F5 or click Run Menu > Start Debugging.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)