An analytic function
1 object = parser.add_argument_group ( 'obejct' ) # parser object initialization speak a plurality of objects
2 object.add_argument () internal parameter
1 flag: Similar parameter name '-H' must be
2 flag_name: Alias parameters like '- -host '
. 3 default: default value when no start parameter specified parameter (the list can be of various types, logical judgment python support)
. 4 type: Analyzing data type (common STR, int, a float)
. 5 dest: this parameter is quite at the location or the option to associate a particular name, the value of the direct use of the name to
6 required: an option to specify when the need arises in the command with this parameter (True or False)
7 Help: use this parameter description option effect (text version)
. 8 action: previously stored value (store_True, store_False), typically with default (True or False) match, set the default value is False, if set to store_True, alternatively, the output value of True False
. 9 nargs: available variable
a may be an integer value N (N number), * (any number) + (one or more)
2 when this variable is added to a space between each parameter, and finally returns a list, each parameter Elements in the table
3 receives specific number represents the number of variables specified maximum received delimitors
3 Parameter List Value Printing
parser.parse_args () call made here is that the overall args, then according to args.dest value of
two cases
Import argparse
Parser = argparse.ArgumentParser ( "test case")
the Test = parser.add_argument_group ( 'the Test')
test.add_argument ( ' -u ',' - user ', type = str, help =' Please enter the user, the default is the root ', default =' the root ')
parser.print_help ()
args = parser.parse_args () # print values
print (args.user)
Basics ~ argparse python module
Guess you like
Origin www.cnblogs.com/danhuangpai/p/10972233.html
Recommended
Ranking