Python ArgumentParser 嵌套参数 [英] Python ArgumentParser nested arguments

查看:25
本文介绍了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 onlyif -a 提供

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆