The Python Oracle

Visual Studio Code: How debug Python script with arguments

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game Looping

--

Chapters
00:00 Question
00:59 Accepted answer (Score 256)
01:41 Answer 2 (Score 93)
02:06 Answer 3 (Score 22)
02:36 Answer 4 (Score 10)
02:56 Thank you

--

Full question
https://stackoverflow.com/questions/5124...

Question links:
[this guide]: https://code.visualstudio.com/docs/pytho...
[image]: https://i.stack.imgur.com/iCrKC.png
[image]: https://i.stack.imgur.com/YS879.png
[image]: https://i.stack.imgur.com/8HJJ5.png

Answer 1 links:
[image]: https://i.stack.imgur.com/GQcKn.png

Answer 2 links:
[image]: https://i.stack.imgur.com/qOtAj.png

Answer 3 links:
[Pawan Kumar]: https://stackoverflow.com/questions/5124...
[Chunde Huang]: https://stackoverflow.com/questions/5124...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #visualstudiocode

#avk47



ACCEPTED ANSWER

Score 336


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"]



ANSWER 2

Score 131


I also noticed that if you run the script by clicking on the debug button that looks like this enter image description here, then the arguments are not passed. However, using Run -> Start Debugging (or its shortcut F5) passed the arguments successfully.




ANSWER 3

Score 15


--key1 value1 value2 --key2 value3 value4

can be passed as

"args": ["--key1=value1", "value2", "--key2=value3", "value4"]

(Combining the two answers by Pawan Kumar and Chunde Huang.)




ANSWER 4

Score 11


Nobody has mentioned this yet, so I thought I'd offer a suggestion that may save you some minutes and certainly some sanity. I set up my launch.json file with an args array, but I couldn't get my args to show up in the terminal when I ran the debugger.

All I had to do was quit and restart VS Code for some reason. Then it worked like a champ.