繁体   English   中英

使用 Visual Studio Code 中的参数运行 Python 程序

[英]Running a Python program with arguments from within the Visual Studio Code

我正在运行一个带有一些命令行参数的 Python 程序。 在 Visual Studio Code 中构建程序时如何提供这些参数?

您可以通过在 launch.json 的args设置中定义参数来将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

如果您使用 Code Runner 扩展,您可以将以下内容添加到您的设置中(点击右上角的“{}”图标以获取 settings.json 文件):

"code-runner.executorMap": { "python": "$pythonPath -u $fullFileName xxx" }

其中 xxx 是您的论点。 这是一个全局更改,因此您必须在处理其他文件时进行更改。

在 2.0.0 版本中执行此操作的一种方法是:

"command": "python ${file} --model_type LeNet5 --prior_file conf1.json --epochs 200",

从终端的命令行运行您的脚本。

根据此处的 vscode 站点

它正在添加类似的

"args" : ["--port", "1593"]

launch.json

我正在运行一个带有一些命令行参数的Python程序。 在Visual Studio Code中构建程序时,如何提供这些参数?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM