在Visual Studio Code中使用自变量运行Python程序 [英] Running a Python program with arguments from within the Visual Studio Code

查看:68
本文介绍了在Visual Studio Code中使用自变量运行Python程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am running a Python program that takes some command line arguments. How can I provide these arguments when I am building a program within the Visual Studio Code?

推荐答案

您可以通过在launch.json的 args 设置中定义参数来将参数传递到程序中,如下所示:

You can pass in the arguments into the program by defining the arguments in the args setting of launch.json as defined below:

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

Further information can be found on the documentation site here: https://github.com/DonJayamanne/pythonVSCode/wiki/Debugging#args

这篇关于在Visual Studio Code中使用自变量运行Python程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆