【发布时间】:2015-07-26 00:39:09
【问题描述】:
我必须解析其中 4 个必须相互绑定的参数,最后 2 个必须是互斥的
group 1 sub_exclusive_1 有 4 个参数,如果其中任何一个已定义,则必须定义所有参数。
组 2 sub_exclusive_2 有 2 个参数,其中只能定义其中 1 个参数,但前提是组 1 中的参数均未定义。
parser = argparse.ArgumentParser(description='Main Description', epilog='Main Epilog')
group_exclusive = parser.add_argument_group('Exclusive')
root_exclusive = group_exclusive.add_mutually_exclusive_group()
sub_exclusive_1 = root_exclusive.add_argument_group()
sub_exclusive_1.add_argument("--firstList", action='store', help = "Help for firstList")
sub_exclusive_1.add_argument("--secondList", action='store', help = "Help for secondList")
sub_exclusive_1.add_argument("--thirdList", action='store', help = "Help for thirdList")
sub_exclusive_1.add_argument("--fourthList", action='store', help = "Help for fourthList")
sub_exclusive_2 = root_exclusive.add_mutually_exclusive_group()
sub_exclusive_2.add_argument("--last", action='store_true', help = "Help for Last")
sub_exclusive_2.add_argument("--first", action='store_true', help = "Help for First")
问题是:
无法将第 1 组参数相互关联。
将
sub_exclusive_1设置为add_argument_group而不是add_mutually_exclusive_group、firstList ... fourthList未显示在 使用-h选项运行程序时的帮助部分。
有什么办法吗?
【问题讨论】: