I'm using Visual Studio Code in order to debug a Python script.
Following this guide , I set up the argument in the launch.json
file:
But when I press on Debug , it says that my argument is not recognized and Visual Studio Code says:
error: unrecognized arguments
As Visual Studio Code is using PowerShell, let's execute the same file with the same argument:
So: the same file, same path, and same argument. In the terminal it is working, but not in Visual Studio Code.
Where am I wrong?
I think the --City and Auckland are used as a single argument. Maybe try separating them like so...
"args": ["--city","Auckland"]
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"]
In Visual Studio, you can pass multiple parameter as convenient and natural way:
--trail=0 --g=0 --V="HO" --save_interval=10 --verbose=True
I just do not know why they will not support this in Visual Studio Code. To list arguments one by one is cumbersome and a bit silly. They just pass the arguments string to the Python parser, and things can be done easily.
--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 .)
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.
File launch.json in the Python project folder path .vscode , tested in Visual Studio Code F5 .
{
// 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",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": ["c", "pwd"],
}
]
}
I managed to run in debugging mode thanks to the comment of @Sourya Dey. Thanks.
这也是愚蠢的,但一定要切换回你想要使用启动配置运行的文件,而不是尝试运行launch.json!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.