Python 命令行工具 -- click

来源:互联网 发布:大数据英文怎么说 编辑:程序博客网 时间:2024/05/28 17:06
看到一个 Python 的命令行工具 - click,很方便,因此记录下,官方主页:http://click.pocoo.org/3/

支持:

  • 命令的任意嵌套
  • 自动生成帮助信息
  • 支持在运行时子命令的延迟加载

安装方法是使用 pip:

pip install click

下面一小段代码是其官方主页的例子,贴出来下:

import click@click.command()@click.option('--count', default=1, help='Number of greetings.')@click.option('--name', prompt='Your name', help='The person to greet.')def hello(count, name): """Simple program that greets NAME for a total of COUNT times.""" for x in range(count): click.echo('Hello %s!' % name)if __name__ == '__main__': hello()

运行:

$ python hello.py --count=3Your name: JohnHello John!Hello John!Hello John!

查看帮助信息:

$ python hello.py --helpUsage: hello.py [OPTIONS]  Simple program that greets NAME for a total of COUNT times.Options:  --count INTEGER  Number of greetings.  --name TEXT      The person to greet.  --help           Show this message and exit.转自: https://segmentfault.com/a/1190000000766489以下是我自己执行的代码和结果 
0 0
原创粉丝点击