Multiple libraries, multiple paths, how many command line parameter parsing libraries does Python have?

Eraser, a funny advanced Internet bug.

This blog will bring you 10 parameter parsing libraries in Python. You must understand these [Module Armory Libraries] that comes with Python. After all, mastering one more library will give you one more way to solve problems.

What is a parameter analysis library

In the period of time for a small Python script to run through python test.py 参数1 参数2 参数3the form, you can pass parameters to the internal Python script library for parsing parameter is the parameter parsing library.

sys.argv

The most traditional way of writing is also the built-in content of Python, such as the following code:

import sys
print(sys.argv)

When you run the Python script by the following command, you can get to a listtype of parameter list.

python test.py 1 2 3

getopt built-in parameter parsing library

For sys.argvpurposes, and get a list, by getoptparameter parsing library, you can obtain parameters.

getoptThe core functions in the library are the getopt.getopt()specific parameters and usage methods. You can refer to this article in the Snowball series .

docopt parameter parsing library

An elegant command line module, you can learn and use through https://github.com/docopt/docopt .

optparse parameter parsing library

The command-line options of the optparse parser. After version 3.2, the optparse module has been deprecated and no further development; the baton is transferred to the argparse module.

To learn how to use it, you can refer to: https://docs.python.org/zh-cn/3/library/optparse.html#module-optparse

argparse parameter parsing library

By pip install argparsethe library to install, use relatively simple, it is the official definition of the command-line options, parameters and sub-command parser.

To learn how to use it, you can refer to: https://docs.python.org/zh-cn/3/library/argparse.html

click parameter parsing library

Click is an open source project of Flask's development team Pallets. It is a third-party module used to quickly create command lines.

For official address and usage, refer to github: https://github.com/pallets/click

fire parameter parsing library

fire is used to automatically generate a command-line interface from any Python object. You can turn any Python component into a command-line interface with just one call to Fire.

The tool library is open sourced by Google.

Open source address: https://github.com/google/python-fire

typer parameter parsing library

Typer is a library for building CLI applications.
Document: https://typer.tiangolo.com

Code: https://github.com/tiangolo/typer

Commando parameter parsing library

Based on argparsethe package, allowing the decorator manner defined commands and parameters.
Open source address: https://github.com/hyde/commando

FLAGS parameter analysis library

If you are doing deep learning related directions, especially often using tensorflow, then FLAGS is an essential command line tool.
The use of this module needs to be based on tensorflow, so it is the last one.

Write at the back

For these high-quality third-party libraries, the recommended order of Eraser is: fire -> click -> argparse -> **getopt **.

The super-high star of these two projects on github also proves that everyone recognizes them.

Multiple libraries, multiple paths, how many command line parameter parsing libraries does Python have?
This blog does not explain all the libraries. After all, mastering a library is already based on the library to solve your problem.

Related Reading

  1. 100 Python crawler tutorials, great crawler tutorials, subscribe now
  2. Python game world (updated, the target number of articles is 50+, subscribe now, all are old fans)
  3. Python crawler lesson, 9 wonderful lectures

Today is the 121st /200th day of continuous writing .
If you want to build a close relationship blogger, you can focus on the public number of the same name dream eraser , close contact with a funny senior Internet worms.
Blogger ID: Dream Eraser, I hope everyone likes , comments , and favorites .

Guess you like

Origin blog.csdn.net/hihell/article/details/115268044