python - 在 VS 代码中调试 Python 脚本时出现无法识别的参数错误
问题描述
我正在尝试在 VS 代码中调试以下脚本:
import os
import argparse
def parseArgs():
parser = argparse.ArgumentParser()
parser.add_argument("-cn", "--cert_names", nargs="+", default=None, help='Provide one or several cert names to be created')
parser.add_argument('-pw', '--password', action='store_true', help='Provide a password for private keys and certs')
args = parser.parse_args()
if not args.cert_names:
print("Please provide one or more cert names")
def main():
parseArgs()
print(args.cert_names)
这是我正在使用的 launch.json 文件:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File and libraries",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode" : false,
"args": ["-cn cert1 cert2 cert3 cert4"],
"cwd": "${fileDirname}",
}
]
}
在 VS 代码中运行调试器后,我收到以下消息: create_certs.py: error: unrecognized arguments: -cn cert1 cert2 cert3 cert4
我想要的是将该列表作为参数传递给脚本,我也尝试过使用“args”:[“--cert_names cert1 cert2 cert3 cert4”],结果相同,
有谁知道我哪里出错了?
解决方案
尝试将 args 分开放置,例如:
"args": ["-cn", "cert1", "cert2", "cert3", "cert4"],
否则,它们都会作为一个巨大的论点通过。
推荐阅读
- javascript - 仅在选项卡上显示元素轮廓,但在单击时不显示
- swift - 为什么 Xcode 不能识别新创建的 UIView?
- go - 使用 mocks 编写单元测试
- visual-studio - 在 VS 代码或任何其他 IDE 中是否存在 ctrl + c (x) / ctrl + v 的第二种状态
- python-3.x - 编写脚本来重命名不正确的文件
- php - 如果在第二页中更改输入,则在一页中显示警报
- python - 找到最大值和最小值
- python - Matplotlib Pie to Bae64 未在 HTML 中显示(Outlook)
- c# - 在 MVC 中检索 JSON 对象和文件
- wmi - 如何在新进程中通过 PowerShell WMI 创建新环境更改