python命令行参数解析实例
来源:互联网 发布:蚁群算法 路径优化 编辑:程序博客网 时间:2024/06/05 07:02
闲言少述,直接上代码
#!/usr/bin/env python
#
#
import json
import getopt, sys
def usage():
print sys.argv[0] + ' -i irt -s status'
print sys.argv[0] + ' -i irt -n seg -t stime'
print sys.argv[0] + ' -h # get help info'
def parse_cmd_line_param():
try:
opts, args = getopt.getopt(sys.argv[1:], "hi:s:n:t:",["help","irt=","status=","seg=","stime="])
except getopt.GetoptError, err:
# print help information and exit;
usage()
sys.exit(2)
irt = None
status = None
seg =0
stime = 0
for op, value in opts:
if op == '-i' or op == '--irt':
irtmp = value
elif op == '-s' or op == '--status':
status = value
elif op == '-n' or op == '--seg':
segnum = int(value)
elif op == '-t' or op == '--stime':
stime = int(value)
elif op == '-h':
usage()
sys.exit()
print "CMD : irt=%s, status=%s, seg=%d, stime=%d" % (irt, status, seg, stime)
def main():
parse_cmd_line_param()
if __name__ == "__main__":
main()
#!/usr/bin/env python
#
#
import json
import getopt, sys
def usage():
print sys.argv[0] + ' -i irt -s status'
print sys.argv[0] + ' -i irt -n seg -t stime'
print sys.argv[0] + ' -h # get help info'
def parse_cmd_line_param():
try:
opts, args = getopt.getopt(sys.argv[1:], "hi:s:n:t:",["help","irt=","status=","seg=","stime="])
except getopt.GetoptError, err:
# print help information and exit;
usage()
sys.exit(2)
irt = None
status = None
seg =0
stime = 0
for op, value in opts:
if op == '-i' or op == '--irt':
irtmp = value
elif op == '-s' or op == '--status':
status = value
elif op == '-n' or op == '--seg':
segnum = int(value)
elif op == '-t' or op == '--stime':
stime = int(value)
elif op == '-h':
usage()
sys.exit()
print "CMD : irt=%s, status=%s, seg=%d, stime=%d" % (irt, status, seg, stime)
def main():
parse_cmd_line_param()
if __name__ == "__main__":
main()
0 0
- python命令行参数解析实例
- 命令行参数解析实例
- python 命令行参数解析
- python 解析命令行参数
- 本文讲述python采用getopt解析命令行输入参数实例
- Python命令行参数解析optparse
- Python的命令行参数解析
- python命令行参数解析OptionParser类
- python命令行参数解析示例应用
- Python解析命令行参数模块getopt
- python 命令行参数解析 argparse简单分析
- Python命令行选项参数解析策略
- python OptionParser 命令行参数解析库
- python 命令行参数解析 argparse简单分析
- python 命令行参数解析的标准模板
- Python命令行参数解析:getopt和argparse
- 【Python 命令行参数解析: optparse 模块】
- python 命令行参数解析 argparse简单分析
- POJ 1308
- python核心编程笔记(1)
- 免费手机开店,管好客、赚多钱!
- Cocos2dx 3.2 横版过关游戏Brave学习笔记(二)
- 【C++ Primer每日一刷之九】创建动态数组
- python命令行参数解析实例
- POJ2892Tunnel Warfare
- 关于tableview的多选问题
- 微软Office与金山WPS Office有何私密关系?
- jsp生成html
- MySQL的information_schema的介绍
- AutoMapper简明教程(学习笔记)
- java生产者消费者多线程同步
- win8.1+vs2013下安装CGAL(含qt、boost、cmake)