Taking Command Line Arguments in Python
When processing command line arguments in Python, you have a few options available:
sys.argv- a raw list of arguments passed to the Python interpreterargparse- Python's standard package for argument parsing (replacesgetoptandoptparse)fileinput.input()- A special function, similar to Ruby's ARGF, that returns the lines of input from standard input or from the list of filenames provided as arguments.docopt- A third-party package that uses the docstring as documentation and configuration for arg parsingclick- A third-party package that uses decorators to map command arguments
Let's look at examples of each option.