码迷,mamicode.com
首页 > 编程语言 > 详细

python OptionParser的用法

时间:2019-04-19 11:47:23      阅读:490      评论:0      收藏:0      [点我收藏+]

标签:option   用法   optparse   app   exit   type   test   code   style   

from optparse import OptionParser

parser = OptionParser(usage = "usage: %prog [options] arg" )
parser.add_option("-u", "--url", action=append, dest="urlname",  help=this is a url)
parser.add_option("-p", "--path", action=append, dest="pathname",  help=this is a path)
(options,args) = parser.parse_args()
print parser.parse_args()
print options, type(options)
print options.urlname, type(options.urlname)
print options.pathname

python test_optparse.py -h输出

Usage: usage111: test_optparse.py [options] arg

Options:
  -h, --help            show this help message and exit
  -u URLNAME, --url=URLNAME
                        this is a url
  -p PATHNAME, --path=PATHNAME
                        this is a path

python test_optparse -u 111 -p 222 输出

(<Values at 0x484b908: {urlname: [111], pathname: [222]}>, [])
{urlname: [111], pathname: [222]} <type instance>
[111] <type list>
[222]

 

python OptionParser的用法

标签:option   用法   optparse   app   exit   type   test   code   style   

原文地址:https://www.cnblogs.com/nevermore29/p/10734846.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!