赞
踩
store:默认action模式,存储值到指定变量。const:配合action="store_const|append_const"使用,默认值
store_const:存储值在参数的const部分指定,多用于实现非布尔的命令行flag。
store_true / store_false:布尔开关。 store_true.默认为False,输入则为true。 store_flase 相反
append:存储值到列表,该参数可以重复使用。
append_const:存储值到列表,存储值在参数的const部分指定。
count: 统计参数简写输入的个数 add_argument("-c", "--gc", action="count")
version 输出版本信息然后退出。
- N (an integer) consumes N arguments (and produces a list)Note that the difference between the default and nargs=1 is that with the default, a single value will be produced, while with nargs=1, a list containing a single value will be produced.
- '?' consumes zero or one arguments
- '*' consumes zero or more arguments (and produces a list)
- '+' consumes one or more arguments (and produces a list)
点击(此处)折叠或打开
# python args_subparse.py -h
usage: args_subparse.py [-h] {create,list,delete} ...
positional arguments:
{create,list,delete} commands
list Listcontents
create Create a directory
delete Remove a directory
optional arguments:
-h, --help show this help message and exit
# python args_subparse.py create -h
usage: args_subparse.py create [-h] [--read-only] dirname
positional arguments:
dirname New directoryto create
optional arguments:
-h, --help show this help message and exit
--read-only Setpermissions to prevent writing to the directory
# python args_subparse.py delete -h
usage: args_subparse.py delete [-h] [--recursive] dirname
positional arguments:
dirname The directory to remove
optional arguments:
-h, --help show this help message and exit
--recursive, -r Remove thecontents of the directory, too
# python args_subparse.py list -h
usage: args_subparse.py list [-h] dirname
positional arguments:
dirname Directory tolist
optional arguments:
-h, --help show this help message and exit
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。