美文网首页
python第三方库

python第三方库

作者: 西伯利亚狼_ | 来源:发表于2018-12-21 10:08 被阅读3次

1. Click

Click是一个用来快速构建好看的命令行接口的第三方库,相比python自带的argparse库要简单很多。

官方示例:

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()
And what it looks like when run:

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

$ python hello.py --help
Usage: 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.

#You can get the library directly from PyPI
$pip install click

相关文章

网友评论

      本文标题:python第三方库

      本文链接:https://www.haomeiwen.com/subject/rkzpkqtx.html