Python点击模块将选项视为参数和错误

发布于 2025-02-09 22:53:54 字数 577 浏览 1 评论 0原文

我在这里做错了什么?我的点击脚本没有参数,但是有多个选项。我的脚本如下:

@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Bonjour°[大白 2025-02-16 22:53:55

因此,毕竟不是点击。这就是我在脚本中所做的。我试图以编程为蝗虫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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文