1 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=3, 默认自动添加了 --help 的选项参数
option 传参时可有可无
argument() 传参时,必须传
示例代码
@click.command()
@click.option(‘--count‘, default=1, help=‘number of greetings‘)
@click.argument(‘name‘)
def hello(count, name):
for x in range(count):
click.echo(‘Hello %s!‘ % name)
了解更多 ,移步 https://www.cnblogs.com/alexkn/p/6980400.html
原文:https://www.cnblogs.com/chenxiyuxiao/p/11396022.html