Visual Studio Code only supports one launch.json file. However, it supports two or more configurations that appear in the debug pane's drop down list (instead of "No Configurations").

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"
}
]
}
Set your desired Config Option in the drop down and put a breakpoint in your Python script, for example on the first line under def main(...) and then press F5 or Run> Start Debugging.
You can run a Python file with arguments without a debugger by selecting a configuration in debug panel, then Ctrl F5 to run it without debugging.
Pro Tip: see the Variable Substitution reference its the perfect way to automate things for the whole team by not hardcoding individuals info or settings in the configs instead using things in Build Pipelines such as Environmental Variables from the get go!
Pro Tip:
Environmental Variables to override any setting.
A settings (aka appSettings.json) file to override the default/shared values.
Default/Shared settings (or hardcoded POCO constructor values).

Later configuration providers overwrite the previous providers. Image courtesy Andrew Lock.
Visual Studio Code only supports one launch.json file. However, it supports two or more configurations that appear in the debug pane's drop down list (instead of "No Configurations").

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"
}
]
}
Set your desired Config Option in the drop down and put a breakpoint in your Python script, for example on the first line under def main(...) and then press F5 or Run> Start Debugging.
You can run a Python file with arguments without a debugger by selecting a configuration in debug panel, then Ctrl F5 to run it without debugging.
Pro Tip: see the Variable Substitution reference its the perfect way to automate things for the whole team by not hardcoding individuals info or settings in the configs instead using things in Build Pipelines such as Environmental Variables from the get go!
Pro Tip:
Environmental Variables to override any setting.
A settings (aka appSettings.json) file to override the default/shared values.
Default/Shared settings (or hardcoded POCO constructor values).

Later configuration providers overwrite the previous providers. Image courtesy Andrew Lock.
You can add a custom task to do this. This deals with the tasks.json. You can add a default tasks.json file for you project (project folder). Follow these steps. Keyboard press Ctrl + Shift + B. It will prompt the following popup

Click on the Configure Build Task If there is already a custom tasks.json file created in the following location .vscode/tasks.json editor will open it. If not, it will give a drop down of suggestions of already existing task runners.
Our intention is to create a custom tasks.json file for our project, so to create one we need to select the Others option from the drop down. Check the screenshot below.

Once you select the Others option, you could see a default tasks.json file will get created from the root directory of the project to the location .vscode/tasks.json. Below is an example of tasks.json.

Now edit the tasks.json file to support Python.
- Change the Command property from
"echo"to"Python" - Keep showOutput as
"Always" - Change args (arguments) from
["Hello World"]to["${file}"](filename) - Delete the last property
problemMatcher - Keep isShellCommand and version properties as unchanged
- Save the changes made
You can now open your .py file and run it nicely with the shortcut Ctrl + Shift + B.
You can use the Python Tools for Visual Studio plugin to configure the python interpreter. Create a new python project and then go to Project Properties | Debug and enter your arguments. You don't need to type python or your script name, only the parameters. Specify the script in General | Startup File. Click Start Debugging to run your script with the parameters specified.
You can enter your command line options by doing the following:
In the Solution Explorer, right click on your project and choose Properties
Click on the Debug tab
In Script Arguments, enter your command line options

Now when you run the project it will run with your command line options.
For example, my code has:
opts, args = getopt.getopt(argv,"p:n:",["points=","startNumber="])
In the Script Arguments, I enter -p 100, -n 1
I am using Visual Studio 2017.
Visual Studio Code: How debug Python script with arguments - Stack Overflow
build - How to run a Python program with arguments from within Visual Studio Code? - Stack Overflow
Why does VS Code IDE make passing command line arguments to the code less than obvious?
Allow "Run Python File in Terminal" to accept script arguments
Videos
I think the --City and Auckland are used as a single argument. Maybe try separating them like so...
Single argument
"args": ["--city","Auckland"]
Multiple arguments and multiple values
Such as:
--key1 value1 value2 --key2 value3 value4
Just put them into the args list one by one in sequence:
"args": ["--key1", "value1", "value2", "--key2", "value3", "value4"]
I also noticed that if you run the script by clicking on the debug button that looks like this
, then the arguments are not passed. However, using Run -> Start Debugging (or its shortcut F5) passed the arguments successfully.
You can pass in the arguments into the program by defining the arguments in the args setting of launch.json as defined below:
json
{
"name": "Python",
"type": "python",
"pythonPath":"${config.python.pythonPath}",
"request": "launch",
"stopOnEntry": true,
"console": "none",
"program": "${file}",
"cwd": "${workspaceRoot}",
"args":["arg1", "arg2"],
"env": {"name":"value"}
}
Further information can be found on the documentation site here: https://github.com/DonJayamanne/pythonVSCode/wiki/Debugging#args
If you use the Code Runner extension you can add the following to your settings (click on the '{}' icon in the top right corner to get the settings.json file):
"code-runner.executorMap": { "python": "$pythonPath -u $fullFileName xxx" }
where xxx is your argument. This is a global change so you have to change when working on other files.
In VS Code there are two run the script buttons (image at https://imgur.com/a/qTjD0Gt) top left or top right. The left button is 'run and debug' (or run with Ctrl-F5) and the right button is 'run' or 'debug'.
Although not obvious, by editing the launch.json file I can pass command line arguments to the left run button. For the right run button, there is no easy way to pass command line arguments/parameters to the code.
Why isn't running code, (a Python script in my case) with command line arguments in the VS Code IDE more intuitively simple?
Does VSCode have a way of doing [title], either natively or through an extension?
I can manage it fine using `launch.json`, but sometimes I want to be able to pass in CLI arguments and not be in debug mode.
I'm aware of the workarounds of "Run it via the command-line" and "Hardcode the args in the file", but neither is a good solution to be honest, and this feels like an incredibly basic feature to be missing.
Hello,
I'm learning Python and using Visual Studio Code as the main editor. One thing I'm trying to learn is how debugging works, and how to debug with VS Code.
My question is: How do I debug a Python script that needs certain starting conditions? More specifically, what if it's a script that takes command line arguments? How do I begin the debugging session while supplying those arguments to start it off?
Thanks!