One: argparse introduction
1. Argparse
Argparse, which is the recommended tool for writing command-line programs in the Python standard library
Parser = Argparse. Argumentparser () creates an instance,
#parser. Parse_args () The Parse_args method is to return some default or specified parameter information from the command-line parameters.
#print Dir (parser)
Parser.add_argument (' Square ', help= ' **2 ', type = int) Add a positional arguments (temporarily does not understand its meaning)
Note: There are currently two types of parameters: positional arguments optional arguments
#parser. Add_argument ('-t ', metavar= ' THREADS ', Type=int, default=20,
# help= ' Num of scan threads for each scan process, by default ')
You can add options to the optional parameter in the above way.
args = Parser.parse_args ()
Print Args.square **2 Note here, args.xxx,xxx must be the name of the parameter added by add_argument
2. Add_argument Method
Add_argument: Read in command-line arguments, the call has multiple parameters
Argumentparser.add_argument (name or flags...) [, Action] [, Nargs] [, Const] [, Default] [, type] [, Choices] [, Required] [, help] [, Metavar] [, Dest])
Name or flags: is a required parameter that accepts the option parameter or is a positional parameter (a string of file names
Https://docs.python.org/2/howto/argparse.html#id1
Chinese reference:
http://songpengfei.iteye.com/blog/1440158 describes each parameter of the Argparse module
http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=21633169&id=4387657 a detailed introduction to the Add_argument method
Python command-line interpreter Argparse