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

问题描述 投票:6回答:3

我正在运行一个Python程序,它接受一些命令行参数。当我在Visual Studio代码中构建程序时,如何提供这些参数?

python build visual-studio-code
3个回答
8
投票

您可以通过在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


0
投票

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

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

0
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.