python解析文件示例
python最近的工作主要是組件兼容性測(cè)試,原有的框架有很多功能還不完善,需要補(bǔ)充!比如,需要將AutoIt腳本的執(zhí)行結(jié)果寫入到Excel中,最后的解決方案是使用本地的log來(lái)解析這個(gè)結(jié)果!
增加了如下一個(gè)類來(lái)完成上述功能:
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文件內(nèi)容類似如下:
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基于xml parse實(shí)現(xiàn)解析cdatasection數(shù)據(jù)
- Python實(shí)現(xiàn)抓取網(wǎng)頁(yè)并且解析的實(shí)例
- Python通過(guò)解析網(wǎng)頁(yè)實(shí)現(xiàn)看報(bào)程序的方法
- python實(shí)現(xiàn)的解析crontab配置文件代碼
- 使用python解析xml成對(duì)應(yīng)的html示例分享
- python解析中國(guó)天氣網(wǎng)的天氣數(shù)據(jù)
- python實(shí)現(xiàn)dnspod自動(dòng)更新dns解析的方法
- python解析發(fā)往本機(jī)的數(shù)據(jù)包示例 (解析數(shù)據(jù)包)
- python解析模塊(ConfigParser)使用方法
- python 解析html之BeautifulSoup
- python實(shí)現(xiàn)網(wǎng)頁(yè)鏈接提取的方法分享
- python正則匹配抓取豆瓣電影鏈接和評(píng)論代碼分享
- Python解析網(wǎng)頁(yè)源代碼中的115網(wǎng)盤鏈接實(shí)例
相關(guān)文章
Python實(shí)現(xiàn)自動(dòng)化處理每月考勤缺卡數(shù)據(jù)
不管是上學(xué)還是上班都會(huì)統(tǒng)計(jì)考勤,有些學(xué)校或公司會(huì)對(duì)每月缺卡次數(shù)過(guò)多(比如三次以上)的人員進(jìn)行處罰。本文提供了Python自動(dòng)處理考勤和日志缺失的方法,需要的可以參考一下2022-06-06pandas如何篩選某個(gè)列值是否位于某個(gè)列表內(nèi)
這篇文章主要介紹了pandas如何篩選某個(gè)列值是否位于某個(gè)列表內(nèi)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-02-02Python實(shí)現(xiàn)求解括號(hào)匹配問(wèn)題的方法
這篇文章主要介紹了Python實(shí)現(xiàn)求解括號(hào)匹配問(wèn)題的方法,涉及Python基于棧的字符串遍歷、判斷、運(yùn)算解決括號(hào)匹配相關(guān)操作技巧,需要的朋友可以參考下2018-04-04Python實(shí)現(xiàn)學(xué)生管理系統(tǒng)的示例代碼
學(xué)生管理系統(tǒng)是一個(gè)常見(jiàn)的應(yīng)用程序,它可以幫助學(xué)校、教育機(jī)構(gòu)或教師管理學(xué)生的信息,本文將介紹如何利用Python開(kāi)發(fā)一個(gè)學(xué)生管理系統(tǒng),需要的可以參考一下2023-07-07全網(wǎng)最全python庫(kù)selenium自動(dòng)化使用詳細(xì)教程
這篇文章主要介紹了python庫(kù)selenium自動(dòng)化使用詳細(xì)教程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2021-01-01Python中Dataframe元素為不定長(zhǎng)list時(shí)的拆分分組
本文主要介紹了Python中Dataframe元素為不定長(zhǎng)list時(shí)的拆分分組,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03