Python ArgumentParser嵌套参数 [英] Python ArgumentParser nested arguments
本文介绍了Python ArgumentParser嵌套参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建带有以下签名的参数解析器:
I want to create argument parser with following signature:
./myapp [-a [-b BVAL] | -c]
换句话说,用户只有在提供参数-a
的情况下才可以提供参数-b BVAL
.
In other words, user could provide argument -b BVAL
only in case if he provided argument -a
.
创建-a
和-c
的互斥组非常容易,但是我不知道如何创建关系allow -b only if -a provided
It's quite easy to create mutually exclusive group of -a
and -c
, but I can't figure out how to create relationship allow -b only if -a provided
推荐答案
Docopt 就像我一样通缉.太棒了!
Docopt does it just as I wanted. Terrific!
docopt('./myapp [-a [-b BVAL] | -c]')
这篇关于Python ArgumentParser嵌套参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文