[Notes] python argparse module

Module introduced way:

import argparse

The description parameter may be used to describe the script information into use, can be null

parser = argparse.ArgumentParser(description="your script description")  

 

--Verbose added label, the label may be an alias -v, where the action means that appears --verbose / -v when the read parameter when the parameter verbose built dictionary corresponding value is True, and parameter help describe use or meaning --verbose parameter.

parser.add_argument('--verbose', '-v', action='store_true', help='verbose mode') 

Conversion parameters dictionary

args = parser.parse_args()

To ensure that some of the required input parameters, custom labels may require increasing requirement. For example, the following statement, wherein the required label --verbose That parameter is required, and int, and other types of input error.

parser.add_argument('--verbose', required=True, type=int)

  

 

Guess you like

Origin www.cnblogs.com/immortalBlog/p/11225339.html