我要解析的参数,其中其中4必须相互捆绑,而去年2必须是独家Python的argparse不显示帮助消息正确
组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
选项运行程序时显示。
任何解决方案?
确定似乎是合法的,但在这里还有另一个问题,我可以取消激活“group1”的帮助消息,将它作为'epilog'添加到'ArgumentParser'中?这将是一个很好的解决方法 – PYPL
'argparse.SUPPRESS'通常用于表示各种类型的帮助输出。我不知道它是否会在这种情况下工作。您可能需要在每个参数中使用它。 – hpaulj
啊,就是这样!它做我想要的东西:)现在我可以将该部分添加到主说明的结语中 – PYPL