![](/img/trans.png)
[英]Running python script with arguments in microsoft visual studio
[英]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",
從終端的命令行運行您的腳本。
我正在運行一個帶有一些命令行參數的Python程序。 在Visual Studio Code中構建程序時,如何提供這些參數?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.