gpt4 book ai didi

python - 如何将参数列表传递给 python 命令

转载 作者:行者123 更新时间:2023-12-01 07:51:27 24 4
gpt4 key购买 nike

parser = argparse.ArgumentParser(description='Run the app')
skill_list = utils.read_yaml_file('skill_list.yml')
parser.add_argument('skill', choices=skill_list, help="Which skill?")

parser.add_argument('endpoints', default=None, help="Configuration file for the connectors as a yml file")

skill = parser.parse_args().skill
endpoints = parser.parse_args().endpoints

在上面的代码中,我可以传递两个参数,如下所示:

run.py joke endpoints.yml

如果我的“技能”是一个变量列表,这意味着我不知道用户可能传递多少参数。在这种情况下,我可以这样做:

run.py joke command weather endpoints.yml

这里“笑话命令天气”将通过“技能”参数传递。我怎样才能做到这一点?

最佳答案

最好对端点使用 -foo--foo。但是如果你想要完全相同的参数传递顺序。这应该有效

parser.add_argument('skill', choices=skill_list, help="Which skill?", nargs='+')

parser.add_argument('endpoints', default=None, help="Configuration file for the connectors as a yml file")

关于python - 如何将参数列表传递给 python 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56194351/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com