我使用Visual Studio代码来调试Python脚本。
按照本指南,我在启动中设置了参数。json文件:
但是当我按下调试,它说我的参数不被识别,Visual Studio Code说:
错误:无法识别的参数
由于Visual Studio Code使用PowerShell,让我们用相同的参数执行相同的文件:
同样的文件,同样的路径,同样的参数。在终端中它可以工作,但在Visual Studio Code中不行。
我哪里错了?
我使用Visual Studio代码来调试Python脚本。
按照本指南,我在启动中设置了参数。json文件:
但是当我按下调试,它说我的参数不被识别,Visual Studio Code说:
错误:无法识别的参数
由于Visual Studio Code使用PowerShell,让我们用相同的参数执行相同的文件:
同样的文件,同样的路径,同样的参数。在终端中它可以工作,但在Visual Studio Code中不行。
我哪里错了?
当前回答
我还注意到,如果您通过单击调试按钮来运行脚本,它看起来像这样 ,则不传递参数。但是,使用Run -> Start Debugging(或其快捷方式F5)成功传递了参数。
其他回答
我还注意到,如果您通过单击调试按钮来运行脚本,它看起来像这样 ,则不传递参数。但是,使用Run -> Start Debugging(或其快捷方式F5)成功传递了参数。
如果单击“调试python文件”没有传递参数,则在启动中添加“purpose”:[" Debug -in-terminal"]。json文件
{"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"args": ["--experimentName", "Debugging"],
"purpose": ["debug-in-terminal"]
}
]
}
我认为,City和Auckland被用作一个论点。也许试着把它们分开,像这样……
单参数
"args": ["--city","Auckland"]
多个参数和多个值
如:
--key1 value1 value2 --key2 value3 value4
只需将它们依次放入args列表中:
“参数”:[”——key1”、“value1”、“value2”,“——key2”,“value3”,“value4”)
目前还没有人提到这一点,所以我想我可以提供一个建议,可能会节省你一些时间,当然也会让你理智一些。我准备好了我的汽艇。json文件与args数组,但我不能让我的args显示在终端当我运行调试器。
我所要做的就是因为某些原因退出并重新启动VS Code。然后它像冠军一样工作。
文件发布。在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"],
}
]
}