Python powerful command line library click getting started tutorial, pythonclick
Preface
Our game resource processing tools are implemented in Python, including csv parsing, UI material processing, animation resource parsing, batch processing, and automatic packaging of Androd & iOS. This project is inherited by other departments. Because most of the Code does not meet our business needs, we have made a major restructuring. All business code is deleted, and only the python code framework is retained. In the project, the command line Parameter Parsing is self-implemented, extremely not elegant, and has endured for so long. We plan to use click to rewrite the time. So I recently learned the click function. The content of this article is the Getting Started tutorial of click. Beginners can come and learn it together.
Image address: http://click.uoota.com/6/
Supported:
- Arbitrary nesting of commands
- Automatically generate help information
- Support delayed loading of sub-commands during running
The installation method is pip:
pip install click
The following code is an example of its official homepage:
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()
Run:
$ python hello.py --count=3Your name: JohnHello John!Hello John!Hello John!
View help information:
$ 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.
Summary
The preceding section describes how to install and use the command line tool click in Python. I hope the content in this article will help you learn or use python, if you have any questions, you can leave a message.