VSCode:如何使用参数调试 Python 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51244223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VSCode: How debug Python script with arguments
提问by Francesco Mantovani
I'm using VSCode in order to debug a Python script.
我正在使用 VSCode 来调试 Python 脚本。
Following this guideI setup the argument in the launch.json
file
按照本指南,我在launch.json
文件中设置了参数
But when I press on Debug it says that my argument is not recognized:
但是当我按下 Debug 时,它说我的论点不被认可:
As VSCode is using PowerShell
, let's execute the same file with the same argument:
由于 VSCode 正在使用PowerShell
,让我们使用相同的参数执行相同的文件:
So: same file, same path, same argument. In the terminal is working, in VSCode not.
所以:相同的文件,相同的路径,相同的参数。在终端中工作,在 VSCode 中没有。
Where am I wrong?
我哪里错了?
回答by Pawan kumar
I think the --City and Auckland are used as a single arg. Maybe try seperating them like so...
我认为 --City 和 Auckland 用作单个参数。也许尝试像这样分开它们......
Single arg
单个参数
"args": ["--city","Auckland"]
Multiple args and multiple values
多个参数和多个值
such as:
如:
--key1 value1 value2 --key2 value3 value4
--key1 value1 value2 --key2 value3 value4
just put into args
list one by one in sequence:
只需按顺序一一args
列出:
"args": ["--key1", "value1", "value2", "--key2", "value3", "value4"]
"args": ["--key1", "value1", "value2", "--key2", "value3", "value4"]
回答by Chunde Huang
In visual studio, you can pass multiple parameter as convient and natural way:
在visual studio中,您可以以方便和自然的方式传递多个参数:
--trail=0 --g=0 --V="HO" --save_interval=10 --verbose=True
I just do not know why they will not support this in VS code. To list arguments one by one is cumbsome and a bit silly. They just pass the arguments string to the python parser, thing can be done easily.
我只是不知道为什么他们不会在 VS 代码中支持这一点。一个一个地列出参数既麻烦又有点傻。他们只是将参数字符串传递给 python 解析器,事情可以轻松完成。