Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying arguments in launch.json for Python

I want to specify arguments in my launch.json file for debugging. I know I can do the following:

"args": ["--arg1", "value", "--arg2"] 

However, I have a very long list of arguments that is formatted as a space-delimited string. Something like this: "--arg1 value --arg2". I tried specifying:

"args": ["--arg1 value --arg2"] 

But that didn't work. Right now my workflow is to take the string of arguments, run it through a Python script that changes the string into a list and copy paste it in my launch.json file. Is there a better way to do this?

like image 450
Tohiko Avatar asked Sep 21 '17 09:09

Tohiko


People also ask

What is args in json?

args - arguments passed to the program to debug.

How do you pass arguments in Visual Studio Code Python?

A workaround is to have your script ask for the command-line arguments (in the internal Visual Studio Code console). Then just set up Visual Studio Code to always pass in the --interactive argument, and your script will always ask for arguments (with history!) even as you set breakpoints.

How do you pass arguments in Visual Studio Code?

To set command-line arguments in Visual Studio, right click on the project name, then go to Properties. In the Properties Pane, go to "Debugging", and in this pane is a line for "Command-line arguments." Add the values you would like to use on this line. They will be passed to the program via the argv array.


1 Answers

Mind that providing arguments in launch.json works like described until you need key value args.

For example, the command

$ python main.py --verbose --name Test 

has to be coded inside the launch.json arguments line like this:

"args": ["--verbose", "--name=Test"], 

Find a nearly hidden hint in the "Watson" example in Python debug configurations in Visual Studio Code.

like image 50
knobi Avatar answered Sep 16 '22 21:09

knobi