python之脚本参数optparse

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
输出文件

posted @ 2016-04-26 18:07  similarface  阅读(282)  评论(0编辑  收藏  举报