Search code examples
visual-studio-code

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?


Solution

  • Mind that providing arguments in launch.json works like described until you need key/value pair 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.