重新生成命令行界面。

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如何将JButton合并到图形中?   java在每个循环中使用基类类型或派生类类型   JavaSwingGUI应用程序完全是空白的,没有任何内容,而按钮被添加到面板中   java Android获取getDefaultSensor括号时出错   java Spring引导和安全性与AngularJS登录页面   java注销appengine应用程序而不从google注销。通用域名格式   java仅在发生错误或异常时创建日志文件,而不使用log4j   java get json数组和Retrift 2   swing中的java响应映像   为什么java的inputstream。close()块?   java驱动管理器。getConnection()非常冗长   java如何使用joml将标准化向量旋转到一个点   ubuntu将Java程序的输出结果保存到一个文件中   java动态可拖动、可编辑和自动调整大小的文本字段