在 VS 代码中调试 Python 脚本时出现无法识别的参数错误
Unrecognized arguments error when debugging Python script in VS code
我正在尝试在 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:错误:无法识别的参数:-cn cert1 cert2 cert3 cert4
我想要的是将该列表作为参数传递给脚本,
我也尝试过使用“args”:[“--cert_names cert1 cert2 cert3 cert4”],结果相同,
有谁知道我错在哪里?
尝试将参数分开放置,例如:
"args": ["-cn", "cert1", "cert2", "cert3", "cert4"],
否则它们都会作为一个大论点通过。
我正在尝试在 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:错误:无法识别的参数:-cn cert1 cert2 cert3 cert4
我想要的是将该列表作为参数传递给脚本, 我也尝试过使用“args”:[“--cert_names cert1 cert2 cert3 cert4”],结果相同,
有谁知道我错在哪里?
尝试将参数分开放置,例如:
"args": ["-cn", "cert1", "cert2", "cert3", "cert4"],
否则它们都会作为一个大论点通过。