Python点击模块将选项视为参数和错误
我在这里做错了什么?我的点击脚本没有参数,但是有多个选项。我的脚本如下:
@click.command()
@click.option("--error-percent-threshold")
@click.option("--latency-threshold")
@click.option("--node-type")
@click.option("--master-ip", default="0.0.0.0")
def main(node_type, error_percent_threshold, latency_threshold, master_ip):
"""Something"""
if __name__ == '__main__':
main()
现在,当我使用python3脚本运行脚本时以下错误:
error: unrecognized arguments: --node-type=master --latency-threshold=50 --error-percent-threshold=1
为什么单击我的选项作为参数感到困惑?
What am I doing wrong here? My Click script has no arguments but has multiple options. My script is as follows:
@click.command()
@click.option("--error-percent-threshold")
@click.option("--latency-threshold")
@click.option("--node-type")
@click.option("--master-ip", default="0.0.0.0")
def main(node_type, error_percent_threshold, latency_threshold, master_ip):
"""Something"""
if __name__ == '__main__':
main()
Now when I run my script with python3 script.py --node-type=master --latency-threshold=50 --error-percent-threshold=1
I get the following error:
error: unrecognized arguments: --node-type=master --latency-threshold=50 --error-percent-threshold=1
Why is Click confusing my options as arguments?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,毕竟不是点击。这就是我在脚本中所做的。我试图以编程为蝗虫UI。 ARGS正确解析了,但由于某种原因,它们被传递给蝗虫,而蝗虫是一个错误,没有被识别的ARGS错误。我能够使用
sys.argv = [sys.argv [0]]
在我开始在脚本中使用蝗虫之前。So it wasn't Click after all. It was what I was doing in the script. I was trying to spin up Locust UI programatically. The args got parsed correctly but they were being passed to locust for some reason and locust was the one error out with the unrecognized args error. I was able to get around this with a
sys.argv = [sys.argv[0]]
right before I start working with locust in the script.