首页 > 其他 > 详细

NB 的 click 库

时间:2019-08-22 18:23:05      阅读:91      评论:0      收藏:0      [点我收藏+]

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



NB 的 click 库

原文:https://www.cnblogs.com/chenxiyuxiao/p/11396022.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!