摘要:引入了一个的创建创建参数没有开头,创建的是在中显示为而不是至少一个值帮助信息有开头,创建的是最终访问的成员名,默认是存储的值空参数是默认参数是参数
Python argparse
python2.7/3.2 引入了一个 argparse 的module
https://docs.python.org/2/library/argparse.html
https://docs.python.org/3.5/library/argparse.html
import argparse
# 创建parser
parser = argparse.ArgumentParser(description="Process some integers.")
# 创建参数
# "integers" -> 没有 - 开头,创建的是 positional argument
# metavar="N" -> 在usage中显示为 N, 而不是 integers
# type=int
# nargs="+" -> 至少一个值
# help="..." -> 帮助信息
parser.add_argument("integers", metavar="N", type=int, nargs="+",
help="an integer for the accumulator")
# "--sum" -> 有 - 开头,创建的是 optional argument
# dest="accumulate" -> 最终访问的成员名,默认是sum
# action="store_const" -> 存储const的值
# const=sum -> 空参数是sum
# default=max -> 默认参数是max
parser.add_argument("--sum", dest="accumulate", action="store_const",
const=sum, default=max,
help="sum the integers (default: find the max)")
# parse参数
parser.parse_args(["--sum", "7", "-1", "42"])
java
Commons CLI
commons-cli commons-cli 1.4-SNAPSHOT
// create Options object
Options options = new Options();
// add t option
options.addOption("t", false, "display current time");
// parse options
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);
if(cmd.hasOption("t")) {
// print the date and time
}
else {
// print the date
}
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/37821.html
摘要:引入了一个的创建创建参数没有开头,创建的是在中显示为而不是至少一个值帮助信息有开头,创建的是最终访问的成员名,默认是存储的值空参数是默认参数是参数 Python argparse python2.7/3.2 引入了一个 argparse 的modulehttps://docs.python.org/2/library/argparse.htmlhttps://docs.python.o...
摘要:命令行参数详解查看的所有命令行参数,使用命令。我们将会对大部分常用的命令行参数进行一一解释,以加深对能力的认识,更加快捷的在服务端命令行下使用或者调试各种因为对环境不熟悉而出现的问题。 PHP作为一门web开发语言,通常情况下我们都是在Web Server中运行PHP,使用浏览器访问,因此很少关注其命令行操作以及相关参数的使用,但是,特别是在类Unix操作系统上,PHP可以作为一门脚本...
阅读 1310·2021-10-08 10:04
阅读 3734·2021-08-05 10:01
阅读 2449·2019-08-30 11:04
阅读 1953·2019-08-29 15:29
阅读 1088·2019-08-29 15:12
阅读 1833·2019-08-26 12:11
阅读 3280·2019-08-26 11:33
阅读 1321·2019-08-26 10:23