标签: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‘]
标签:option 用法 optparse app exit type test code style
原文地址:https://www.cnblogs.com/nevermore29/p/10734846.html