DEV Community

Wincent Balin
Wincent Balin

Posted on • Originally published at ofdigitalwater.postach.io on

1 3

Print default values of CLI arguments in Python

If you would like to print default values of command-line arguments and if you use the argparse.ArgumentParser class in your Python program, consider setting the formatter_class option to argparse.ArgumentDefaultsHelpFormatter.

Example code:

parser = argparse.ArgumentParser(description=sys.modules[__name__]. __doc__ ,
                                 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-s', '--std', type=float, default=440.0, help='Standard value')
args = parser.parse_args()
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more