argparse上的抽象层。

caipyrinha的Python项目详细描述


argparse上的抽象层。

caipyrinha向argparse.argumentparser添加了2个方法,callbackparse_wc。caipyrinha实例也是可调用的,并且等于使用 parse_wc方法。

使用示例:

# ex.pyimportcaipyrinhaparser=caipyrinha.Caipyrinha(prog="Your Program")parser.add_argument("--version",action='version',version="%(prog)s 0.1")@parser.callback(exit=0,exclusive="group1")deffirst(flags,returns):'''Execute this option and exit'''print"bye bye"@parser.callback(action="store")defsecond(flags,returns):'''set his own return value with his parameter'''returnflags.second@parser.callback("--third",exclusive="group1")defno_used_name(flags,returns):'''you cant use this argument with first'''printreturns.secondimportsysparser(sys.argv[1:])

用法

$ python ex.py --help
usage: Your Program [-h] [--version] [--first] [--second SECOND] [--third]

optional arguments:
  -h, --help       show this help message and exit
  --version        show program's version number and exit
  --first          Execute this option and exit
  --second SECOND  set his own return value with his parameter
  --third          you cant use this argument with first
$ python ex.py --first
bye bye
$ python ex.py --first --second "hello from second"
bye bye
$ python ex.py --first --second "hello from second" --third
usage: Your Program [-h] [--version] [--first] [--second SECOND] [--third]
Your Program: error: argument --third: not allowed with argument --first
$ python ex.py --second "hello from second" --third
hello from second

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
SpringMVC中的java,当我遇到旋度时,SpringMVC中出现错误   java如何从设备获取默认ip地址?   plink运行autosys批处理作业并检查其在java中的状态   java Json数组对象通过控制器[Spring Boot]传递到模型   netbeans将java命令行参数传递给插件   java Android AIDL gen文件导致警告?   java JAXB阻止JAXB与共享实体序列化   由@JsonIdentityInfo序列化的对象的java反序列化   postgresql java数组插入postgres   Java圆环碰撞检测   在Java中提取JSON键名   jdk1中的java内存泄漏。7   java Spring 3@Autowired注释问题