We can start a program with additional arguments, in the command line. Python programs can start with command-line arguments. Let's look at an example:
$ python program_name.py img.jpg
Here, program_name.py and img.jpg are arguments.
Now, we are going to use modules to get the arguments:
Module |
Use |
Python version |
optparse |
Deprecated |
< 2.7 |
sys |
All arguments in sys.argv (basic) |
All |
argparse |
Building a command-line interface |
>= 2.3 |
fire |
Automatically generating Command-Line Interfaces (CLIs) |
All |
docopt |
Creating CLIs interfaces |
>= 2.5 |