您的位置:首页 > 运维架构

python之脚本参数optparse

2016-04-26 18:07 393 查看
import optparse
usage = "myprog[ -f <filename>][-s <xyz>] arg1[,arg2..]"
opter=optparse.OptionParser(usage)
opter.add_option("-f","--format",action="store_true",dest="format",help="format print")
opter.add_option("-t", "--table", action="store", type="string", dest="table",help=u"输入一个表名")
opter.add_option("-q", "--query", action="store", type="string", dest="term",help=u"查询的关键字")
opter.add_option("-o", "--output", action="store", type="string", dest="outfile",help=u"输出文件")
opt,args=opter.parse_args()


输入:-h

Options:
-h, --help show this help message and exit
-f, --format format print
-t TABLE, --table=TABLE
输入一个表名
-q TERM, --query=TERM
查询的关键字
-o OUTFILE, --output=OUTFILE
输出文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: