python optparse 长选项 短选项使用
2014-08-26 17:44
190 查看
import optparse, os, socket, time
def parse_args():
usage = """
python test.py test
"""
parser = optparse.OptionParser(usage)
help = "Iplist File"
parser.add_option("-f","--file", dest='iplistfile',default='iplist.txt',help=help)
help = "Cmd File"
parser.add_option("-c","--config", dest='cmdfile',default='config',help=help,metavar="FILE")
help = "Log File"
parser.add_option("-o","--output", dest='logfile',default='7z.log',help=help)
help = "Process Num"
parser.add_option("-p","--process", type=int,default=20,help=help)
help = "The interface to listen on. Default is localhost."
parser.add_option('--iface', help=help, default='localhost')
help = "The number of seconds between sending bytes."
parser.add_option('--delay', type='float', help=help, default=.1)
help = "The port to listen on. Default to a random available port."
parser.add_option('--port', type='int', default=5000,help=help)
help = "The number of bytes to send at a time."
parser.add_option('--num-bytes', type='int', help=help, default=10)
options, args = parser.parse_args()
if len(args) != 1:
parser.error('Provide exactly one poetry file.')
poetry_file = args[0]
if not os.path.exists(args[0]):
parser.error('No such file: %s' % poetry_file)
return options, poetry_file
def parse_args():
usage = """
python test.py test
"""
parser = optparse.OptionParser(usage)
help = "Iplist File"
parser.add_option("-f","--file", dest='iplistfile',default='iplist.txt',help=help)
help = "Cmd File"
parser.add_option("-c","--config", dest='cmdfile',default='config',help=help,metavar="FILE")
help = "Log File"
parser.add_option("-o","--output", dest='logfile',default='7z.log',help=help)
help = "Process Num"
parser.add_option("-p","--process", type=int,default=20,help=help)
help = "The interface to listen on. Default is localhost."
parser.add_option('--iface', help=help, default='localhost')
help = "The number of seconds between sending bytes."
parser.add_option('--delay', type='float', help=help, default=.1)
help = "The port to listen on. Default to a random available port."
parser.add_option('--port', type='int', default=5000,help=help)
help = "The number of bytes to send at a time."
parser.add_option('--num-bytes', type='int', help=help, default=10)
options, args = parser.parse_args()
if len(args) != 1:
parser.error('Provide exactly one poetry file.')
poetry_file = args[0]
if not os.path.exists(args[0]):
parser.error('No such file: %s' % poetry_file)
return options, poetry_file
相关文章推荐
- Python模块整理(七):选项模块Optparse
- python模块整理24-Optparse选项参数
- python optparse 模块使用
- Python命令行选项处理模块Getopt使用
- Python模块整理:选项模块Optparse
- Python命令行参数解析模块optparse使用实例
- python optparse模块使用实例
- python里使用正则表达式的选项参数
- 我的python学习之路---命行选项模块optparse
- python命令行参数处理模块 optparse 使用参考
- Python中optparse模块使用学习
- 如果使用Python,不同的阶段应该有多种选项,反而容易让人困惑
- Python使用argparse命令行选项计算文件中单词个数
- Python:使用 optparse 处理命令行参数
- Python:使用 optparse 处理命令行参数
- python里使用正则表达式的内嵌功能选项标志
- python里使用正则表达式的内嵌功能选项标志
- python argparse模块解析命令行选项简单使用
- 关于在组件GIS开发中使用Python的一点补充说明
- Python使用Com组件及Access查询分析类实现