重新生成命令行界面。

bacli的Python项目详细描述


巴克利

重新生成命令行界面。

bacli是一个模块,它包装了argparse的命令行参数解析功能,以便于使用。任何python函数都可以转换为程序的入口点。只需添加bacli.commanddecorator,就可以直接从命令行调用函数(使用参数、文档和正确的类型!).

使用量

""" example.py: This file serves as a demonstration of the bacli functionality. """

import bacli

bacli.setDescription(__doc__)

@bacli.command
def run():
    """ Run the model. """
    print("Running")

@bacli.command
def train(iterations: int, batch_size: int=32):
    """ Train the model. """
    print("Training model")
    print("{} iterations".format(iterations))
    print("batch size of {}".format(batch_size))

然后可以如下使用:

> python example.py -h
usage: example.py [-h] subcommand ...

example.py: This file serves as a demonstration of the bacli functionality.

positional arguments:
  subcommand  Select one of the following subcommands:
    run       Run the model.
    train     Train the model.

optional arguments:
  -h, --help  show this help message and exit

> python example.py run
Running

> python example.py train -h
usage: example.py train [-h] [--batch_size BATCH_SIZE] iterations

Train the model.

positional arguments:
  iterations            type: int

optional arguments:
  -h, --help            show this help message and exit
  --batch_size BATCH_SIZE
                        type: int, default=32

> python example.py train 10 --batch_size 64
Training model
10 iterations
batch size of 64

即将推出的功能

  • 支持变量参数(*args和**kwargs)
  • 参数支持文档
  • 支持参数的别名(可以使用first leter作为快捷方式)

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

推荐PyPI第三方库


热门话题
java爬虫获取外部网站搜索结果   java Bluestack未连接到eclipse   java如何从ConstraintViolationException Hibernamte获取数据库字段名   HttpResponse HttpResponse=httpClient引发java运行时错误。执行(httpPost);   Jama中矩阵的java点积和叉积   java有什么方法可以唯一地识别可扩展设备吗?   java我需要用*来写我的名字,但我不断遇到一个错误,我对编码很陌生   java变量是在内部类中访问的。需要被宣布为最终决定。但我不想宣布最终结果   java如何缩短base64图像字符串,Android?   JavaSpringMVC:计划方法不自动触发   图形学习Java 2D API的好资源是什么?   如何在java中对方法进行排队   java JavaFX多行   java Selenium无法在[链接]上找到基于CSS元素的密码字段元素http://www.cartasi.it/gtwpages/index.jsp   Java中的equals()和hashCode()契约   软删除情况下的java Hibernate二级缓存   java为什么这段代码要两次调用这些方法?