Powerful command-line libraries in Python click Get Started Tutorial

Source: Internet
Author: User
Click is a command-line tool for Python and is extremely useful. Don't believe me? A try to know. The following article mainly introduces you to Python's powerful command-line library Click, the need for friends can refer to the study, the following to see together.

Objective

Our game resource processing tools are implemented in Python, including CSV parsing, UI material handling, animation resource parsing, batch processing, Androd&ios automatic packaging, and more. The project was inherited by other departments, and because the vast majority of the code did not meet our business needs, it was heavily refactored. All business code was removed, and only the Python code framework was preserved. The command line parameter parsing in the project is self-fulfilling, extremely not elegant, and endure for so long. I'm going to find time to rewrite it with Click. So recently learned click, the following article is the click of the introductory tutorial, beginners can come together to learn.

Website Image address: http://click.uoota.com/6/

Support:

    1. Arbitrary nesting of commands

    2. Automatically generate Help information

    3. Supports lazy loading at run-time subcommands

The installation method is to use PIP:

PIP Install click

The following short snippet of code is an example of its official homepage, affixed to the following:

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 the 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 This  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.

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.