python命令行参数解析实例
2014-09-02 11:28
549 查看
闲言少述,直接上代码
#!/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()
相关文章推荐
- python命令行参数解析OptionParser类用法实例
- Python命令行参数解析模块optparse使用实例
- Python命令行参数解析模块getopt使用实例
- python 解析html基础 HTMLParser库,方法,及代码实例
- Python实例讲解 -- 解析xml
- python正则捕获日志解析实例
- Python3基础之条件与循环控制实例解析
- PYTHON 与C相互交互调用实例解析
- python生成日历实例解析
- python 解析XML python模块xml.dom解析xml实例代码
- python 解析XML python模块xml.dom解析xml实例代码
- python中enumerate的用法实例解析
- python实例31[解析buildlog]
- CDays-3 习题一 (处理命令行参数)及相关内容解析。Python getopt 简介
- python 解析XML python模块xml.dom解析xml实例代码
- python实例31[解析buildlog]
- Python PDF 文件解析及二次处理 实例
- Python开发实例分享bt种子爬虫程序和种子解析
- python中enumerate的用法实例解析