Python powerful command line library click getting started tutorial, pythonclick

Source: Internet
Author: User

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:

  1. Arbitrary nesting of commands
  2. Automatically generate help information
  3. 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.