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:
Arbitrary nesting of commands
Automatically generate Help information
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.