According to the official documentation "Python debugging in VS Code", launch.json can be configured to run with specific command line arguments, or you can use ${command:pickArgs} to input arguments at run time.
Examples of putting arguments in launch.json:
- Specifying arguments in launch.json for Python
- Visual Studio Code: How debug Python script with arguments
However, I would rather use but I would rather use ${command:pickArgs} because it makes it easier to test multiple times with different values.
The first time I tried this, I allowed VS Code to create launch.json. By default it contained the following:
"args": [
"${command:pickArgs}"
]
When I run the file, I get a dialog for inputting arguments:
However, if I put in multiple arguments, they get wrapped in quotes and treated as a single string argument. In a case where, e.g. the arguments are supposed to be numeric, an error is generated. For example, if I pass in 4 7, which both need to be cast to int, sys.argv[1] gets the value '4 7' rather than '4', yielding the error
invalid literal for int() with base 10: '4 7'
I have tried comma-separating the arguments, and putting quotes around them, and what I get is sys.argv[1] with values like '4, 7' or '"4", "7"'. Needless to say, these don't work either.
I've seen examples online of a launch.json configuration as follows:
"args": "${command:pickArgs}"
That is, there are no brackets around ${command:pickArgs}. However, this generates a problem in that if there are spaces in the path to the Python interpreter, the path gets broken apart at the spaces. See, for example:
The solution seems to be to put the brackets in, which is what I started with in the first place. Since that's what VS Code did automatically, I'm not sure where the varying examples are coming from (with or without brackets) and can't find documentation on this other than the very short mention of ${command:pickArgs} in the official documentation I linked at the very beginning.
So, I have not been able to figure out a way to pass in multiple arguments using ${command:pickArgs} (as opposed to hard-coding directly in launch.json), and the only promising solution (remove the brackets) is poorly documented, generates other errors, and the solution seems to be to put the brackets back in.
Is this possible to do at all?

python script.py arg1 arg2.