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 类与元类的深度挖掘 II【经验】
May 06 Python
numpy.transpose对三维数组的转置方法
Apr 17 Python
Tensorflow使用tfrecord输入数据格式
Jun 19 Python
Python连接Mssql基础教程之Python库pymssql
Sep 16 Python
python3 中文乱码与默认编码格式设定方法
Oct 31 Python
Python 堆叠柱状图绘制方法
Jul 29 Python
Python3 文章标题关键字提取的例子
Aug 26 Python
PYTHON发送邮件YAGMAIL的简单实现解析
Oct 28 Python
使用Python将图片转正方形的两种方法实例代码详解
Apr 29 Python
一些关于python 装饰器的个人理解
Aug 31 Python
python中使用 unittest.TestCase单元测试的用例详解
Aug 30 Python
Python中如何处理常见报错
Jan 18 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中的CMS的涵义
2007/03/11 PHP
PHP中把有符号整型转换为无符号整型方法
2015/05/27 PHP
yii2.0框架多模型操作示例【添加/修改/删除】
2020/04/13 PHP
利用404错误页面实现UrlRewrite的实现代码
2008/08/20 Javascript
Jquery Ajax学习实例3 向WebService发出请求,调用方法返回数据
2010/03/16 Javascript
Jquery插件 easyUI属性汇总
2011/01/19 Javascript
$.getJSON在IE下失效的原因分析及解决方法
2013/06/16 Javascript
jquery图片滚动放大代码分享(1)
2015/08/25 Javascript
javascript实现C语言经典程序题
2015/11/29 Javascript
JS使用onerror捕获异常示例
2016/08/03 Javascript
基于jquery实现的鼠标悬停提示案例
2016/12/11 Javascript
详解Vue2.x-directive的学习笔记
2017/07/17 Javascript
Vue实现点击时间获取时间段查询功能
2020/08/21 Javascript
微信小程序实现点击图片旋转180度并且弹出下拉列表
2018/11/27 Javascript
Python安装第三方库的3种方法
2015/06/21 Python
使用Python对MySQL数据操作
2017/04/06 Python
django进阶之cookie和session的使用示例
2018/08/17 Python
python 不同方式读取文件速度不同的实例
2018/11/09 Python
pygame游戏之旅 添加游戏暂停功能
2018/11/21 Python
python实现微信定时每天和女友发送消息
2019/04/29 Python
Django CBV类的用法详解
2019/07/26 Python
Python闭包及装饰器运行原理解析
2020/06/17 Python
互斥锁解决 Python 中多线程共享全局变量的问题(推荐)
2020/09/28 Python
matplotlib绘制正余弦曲线图的实现
2021/02/22 Python
Allen Edmonds官方网站:一家美国优质男士鞋类及配饰制造商
2019/03/12 全球购物
英国花园、DIY、电器和家居用品商店:Robert Dyas
2019/03/18 全球购物
SHEIN台湾:购买最新流行女装服饰
2019/05/18 全球购物
澳大利亚一站式数码相机商店:CameraPro
2020/03/09 全球购物
学校岗位设置方案
2014/01/16 职场文书
学校招生宣传广告词
2014/03/19 职场文书
入党积极分子自我鉴定范文
2014/03/25 职场文书
群众路线领导班子整改方案
2014/10/25 职场文书
2014年班组工作总结
2014/11/20 职场文书
新郎婚礼答谢词
2015/01/04 职场文书
个人工作违纪检讨书
2015/05/05 职场文书
Python+OpenCV实现在图像上绘制矩形
2022/03/21 Python