The first is about setting the-h/--help parameter
Description: Before help information can be used to describe the help
Prog: Describes the name of the program in the Help information
Epilog: After Help information
Usage: Describes the purpose of the program
ADD_HELP: The default is true, set to false, can not display the Help information, execution-h/--help will be error
Conflict_handler: Resolving parameter conflicts
Prefix_chars: Parameter prefix, default to "-"
Fromfile_prefix_chars: Set prefix character, put in file name, read and execute parameters
Argument_default: Global default values for parameters
Description/epilog
#-*-Coding:utf-8-*-__author__ = "MuT6 sch01ar" Import argparseparser = Argparse. Argumentparser (description= "The help of Python") parser.add_argument ("-T", "--thread", help= "thread Run", action= " Store_true ") args = Parser.parse_args () If Args.thread: print (args) Else: print (" Error ")
Execute parameter-H
Run results
Prog/usage
#-*-Coding:utf-8-*-__author__ = "MuT6 sch01ar" Import argparseparser = Argparse. Argumentparser (description= "The Help in Python", epilog= "End of Help", usage= "python Run Thread") parser.add_argument ("- T ","--thread ", help=" thread Run ", action=" store_true ") args = Parser.parse_args () If Args.thread: print (args) Else: print ("Error")
Run results
The default is
If prog and usage are not set, the default, prog, and usage settings are displayed and the usage
Add_help
#-*-Coding:utf-8-*-__author__ = "MuT6 sch01ar" Import argparseparser = Argparse. Argumentparser (description= "The Help in Python", epilog= "End of Help", Add_help=false) parser.add_argument ("-T", "-- Thread ", help=" thread Run ", action=" store_true ") args = Parser.parse_args () If Args.thread: print (args) Else: Print ("Error")
Run results
Conflict_handler
When the parameters are repeated, the program will error, the Conflict_handler set to Resovle can be resolved
#-*-Coding:utf-8-*-__author__ = "MuT6 sch01ar" Import argparseparser = Argparse. Argumentparser (description= "The Help in Python", epilog= "End of Help") parser.add_argument ("-T", "--thread", help= " Thread Run ", action=" Store_true ") parser.add_argument ("-T ","--thread ", help=" thread run (2) ", action=" Store_true ") args = Parser.parse_args () If Args.thread: print (args) Else: print ("Error")
Run, error
To Argparse. Argumentparser () Add conflict_handler= "resolve"
#-*-Coding:utf-8-*-__author__ = "MuT6 sch01ar" Import argparseparser = Argparse. Argumentparser (description= "The Help in Python", epilog= "End of Help", conflict_handler= "resolve") parser.add_argument ("-T", "--thread", help= "thread Run", action= "Store_true") parser.add_argument ("-T", "--thread", help= "thread run (2)", action= "Store_true") args = Parser.parse_args () If Args.thread: print (args) Else: print ("Error")
Run results
The original-t/--thread parameter is overwritten
Python command Module Argparse Learning notes (i)