python解析文件示例


Posted in Python onJanuary 23, 2014

python最近的工作主要是组件兼容性测试,原有的框架有很多功能还不完善,需要补充!比如,需要将AutoIt脚本的执行结果写入到Excel中,最后的解决方案是使用本地的log来解析这个结果!

增加了如下一个类来完成上述功能:

class AutoItResultParser():
    def ParseResult(self, vm_result, log_file):
        for case_result in vm_result.cases_results:
            self.__ModifyAutoItResult(case_result, log_file)    def __ModifyAutoItResult(self, result, log_file):
        items = []
        myfile = open(log_file, 'rb')
        line = myfile.readline()
        count = 0
        while('' != line):
            items.append(line.split(':')[0])
            count += 1
            if(count % 2 == 0):
                items.append(line.split(':')[1])
            line = myfile.readline()
        myfile.close()
        fail_scripts = []
        length = len(items)
        arr = list(range(2, length, 3))
        for i in arr:
            test = items[i].lower()
            if test.rfind('success') == -1:
                fail_scripts.append((items[i - 2], items[i - 1]))
        for script in fail_scripts:
            if script[0] == result.case_name:
                if script[1] == 'Installation':
                    result.install_script_success = False
                elif script[1] == 'Launch':
                    result.launch_script_success = False
                elif script[1] == 'Function':
                    result.function_script_success = False
                else:
                    result.uninstall_script_success = False

这里的log_file文件内容类似如下:

VisualStudio2010_StandaloneProfiler:
Installation:   Success
VisualStudio2010_StandaloneProfiler:
Launch:         Success
VisualStudio2010_StandaloneProfiler:
Function:       Fail
TaobaoBrowser_2.0.0:
CitrixOfflinePlugin_6.5:
Installation:   Success
CitrixOfflinePlugin_6.5:
Function:       Success
TrusteerRapport:
TNTShippingTools:
Installation:   Success
TNTShippingTools:
Launch:         Success
WGET_1.11.4:
Installation:   Success
VisualStudio2010_StandaloneProfiler:
Uninstallation: Success
TNTShippingTools:
Uninstallation: Fail
Python 相关文章推荐
Python正则表达式教程之三:贪婪/非贪婪特性
Mar 02 Python
用Python删除本地目录下某一时间点之前创建的所有文件的实例
Dec 14 Python
tensorflow实现加载mnist数据集
Sep 08 Python
python实现祝福弹窗效果
Apr 07 Python
Python shelve模块实现解析
Aug 28 Python
Django Admin中增加导出CSV功能过程解析
Sep 04 Python
Python scipy的二维图像卷积运算与图像模糊处理操作示例
Sep 06 Python
Python 网络编程之TCP客户端/服务端功能示例【基于socket套接字】
Oct 12 Python
Django项目使用ckeditor详解(不使用admin)
Dec 17 Python
tensorflow之tf.record实现存浮点数数组
Feb 17 Python
Python tornado上传文件的功能
Mar 26 Python
python利用appium实现手机APP自动化的示例
Jan 26 Python
python回调函数的使用方法
Jan 23 #Python
python中的对象拷贝示例 python引用传递
Jan 23 #Python
使用scrapy实现爬网站例子和实现网络爬虫(蜘蛛)的步骤
Jan 23 #Python
python使用scrapy解析js示例
Jan 23 #Python
php使用递归与迭代实现快速排序示例
Jan 23 #Python
python实现批量转换文件编码(批转换编码示例)
Jan 23 #Python
python写的一个文本编辑器
Jan 23 #Python
You might like
PHP 字符串 小常识
2009/06/05 PHP
Laravel 5 框架入门(四)完结篇
2015/04/09 PHP
求解开jscript.encode代码的asp函数
2007/02/28 Javascript
window.opener用法和用途实例介绍
2013/08/19 Javascript
关于jQuery中.attr()和.prop()的问题探讨
2013/09/06 Javascript
开发中可能会用到的jQuery小技巧
2014/03/07 Javascript
jquery引用方法时传递参数原理分析
2014/10/13 Javascript
jQuery团购倒计时特效实现方法
2015/05/07 Javascript
JavaScript中数组继承的简单示例
2015/07/29 Javascript
angularJS Provider、factory、service详解及实例代码
2016/09/21 Javascript
vue双向数据绑定原理探究(附demo)
2017/01/17 Javascript
Bootstrap学习笔记之进度条、媒体对象实例详解
2017/03/09 Javascript
Nodejs回调加超时限制两种实现方法
2017/06/09 NodeJs
JavaScript中数组常见操作技巧
2017/09/01 Javascript
原生js实现简单的模态框示例
2017/09/08 Javascript
自定义PC微信扫码登录样式写法
2017/12/12 Javascript
angular5 httpclient的示例实战
2018/03/12 Javascript
详解vue中组件参数
2018/07/09 Javascript
微信小程序日历/日期选择插件使用方法详解
2018/12/28 Javascript
微信小程序实现购物页面左右联动
2019/02/15 Javascript
vue elementUI 表单校验功能之数组多层嵌套
2019/06/04 Javascript
three.js 如何制作魔方
2020/07/31 Javascript
[02:05]2014DOTA2西雅图国际邀请赛 BBC第二天小组赛总结
2014/07/11 DOTA
python使用clear方法清除字典内全部数据实例
2015/07/11 Python
Python错误提示:[Errno 24] Too many open files的分析与解决
2017/02/16 Python
Python+Wordpress制作小说站
2017/04/14 Python
Python检测网络延迟的代码
2018/05/15 Python
Python3 实现减少可调用对象的参数个数
2019/12/20 Python
用Python绘制漫步图实例讲解
2020/02/26 Python
IE支持HTML5的解决方法
2009/10/20 HTML / CSS
简述数组与指针的区别
2014/01/02 面试题
初一地理教学反思
2014/01/16 职场文书
理工学院学生自我鉴定
2014/02/23 职场文书
2015年暑期社会实践总结
2015/07/13 职场文书
Vue CLI中模式与环境变量的深入详解
2021/05/30 Vue.js
MySQL创建定时任务
2022/01/22 MySQL