Skip to content
Generic filters
Exact matches only

3 Ways to Handle Args in Python. A Straight to the Point Guide | by Dardan Xhymshiti | Aug, 2020

If you want to have a proper command-line interface for your application, the argparse is the module to go. This is a full-fledge module that offers out-of the-box arguments parsing, help messages and automated error throwing when arguments get misused. This module comes pre-installed with Python.

To fully utilize the functionalities provided by argparse, it takes some time to master. As a start up, consider the following example of

After initializing an object of ArgumentParses, we add all the expected arguments by using add_argument function. This function receives a number of parameters among which the argument name (eg. --name), the destination variable, the expected data type, the help message to display etc.

Triggering as:

would return

To find more about this module, take a look at argparse docs.