在VSCode文件中安装时,launch.json
中的命令行参数工作得很好。
但是当使用" Python :在终端中运行Python文件“(运行,而不是调试)时,launch.json
中的参数似乎不会出现在sys.argv
中。
在使用" Python :在终端中运行Python文件“时,是否有方法将命令行参数传递给Python代码?
发布于 2022-09-05 20:51:47
您可以通过JSON内部的args
传递参数。
示例:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: app.py",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/app.py",
"args" : ["arg1", "arg2", "arg3"]
}
]
}
来源:VSCode
https://stackoverflow.com/questions/73614523
复制相似问题