手机
当前位置:查字典教程网 >脚本专栏 >python >python解析文件示例
python解析文件示例
摘要:python最近的工作主要是组件兼容性测试,原有的框架有很多功能还不完善,需要补充!比如,需要将AutoIt脚本的执行结果写入到Excel中...

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获取糗百图片代码实例

Python常见文件操作的函数示例代码

python操作xml文件示例

python合并文本文件示例

python多线程编程方式分析示例详解

python 获取文件列表(或是目录例表)

python使用scrapy解析js示例

python获得图片base64编码示例

python迭代器的使用方法实例

python pdb调试方法分享

精品推荐
分类导航