我正在运行一个Python程序,它接受一些命令行参数。当我在Visual Studio代码中构建程序时,如何提供这些参数?
您可以通过在launch.json的args
设置中定义参数来将参数传递到程序中,如下所示:
json
{
"name": "Python",
"type": "python",
"pythonPath":"${config.python.pythonPath}",
"request": "launch",
"stopOnEntry": true,
"console": "none",
"program": "${file}",
"cwd": "${workspaceRoot}",
"args":["arg1", "arg2"],
"env": {"name":"value"}
}
更多信息可以在文档网站上找到:https://github.com/DonJayamanne/pythonVSCode/wiki/Debugging#args
在2.0.0版本中执行此操作的一种方法是:
"command": "python ${file} --model_type LeNet5 --prior_file conf1.json --epochs 200",
如果您使用Code Runner扩展程序,则可以将以下内容添加到您的设置中(单击右上角的“{}”图标以获取settings.json文件):
“code-runner.executorMap”:{“python”:“$ pythonPath -u $ fullFileName xxx”}
其中xxx是你的论点。这是一个全局更改,因此您在处理其他文件时必须更改。