python解析文件示例
更新時間:2014年01月23日 16:58:27 作者:
這篇文章主要介紹了python解析文本文件示例,大家參考使用吧
python最近的工作主要是組件兼容性測試,原有的框架有很多功能還不完善,需要補充!比如,需要將AutoIt腳本的執(zhí)行結(jié)果寫入到Excel中,最后的解決方案是使用本地的log來解析這個結(jié)果!
增加了如下一個類來完成上述功能:
復制代碼 代碼如下:
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實現(xiàn)解析cdatasection數(shù)據(jù)
- Python實現(xiàn)抓取網(wǎng)頁并且解析的實例
- Python通過解析網(wǎng)頁實現(xiàn)看報程序的方法
- python實現(xiàn)的解析crontab配置文件代碼
- 使用python解析xml成對應的html示例分享
- python解析中國天氣網(wǎng)的天氣數(shù)據(jù)
- python實現(xiàn)dnspod自動更新dns解析的方法
- python解析發(fā)往本機的數(shù)據(jù)包示例 (解析數(shù)據(jù)包)
- python解析模塊(ConfigParser)使用方法
- python 解析html之BeautifulSoup
- python實現(xiàn)網(wǎng)頁鏈接提取的方法分享
- python正則匹配抓取豆瓣電影鏈接和評論代碼分享
- Python解析網(wǎng)頁源代碼中的115網(wǎng)盤鏈接實例
相關(guān)文章
Python實現(xiàn)自動化處理每月考勤缺卡數(shù)據(jù)
不管是上學還是上班都會統(tǒng)計考勤,有些學校或公司會對每月缺卡次數(shù)過多(比如三次以上)的人員進行處罰。本文提供了Python自動處理考勤和日志缺失的方法,需要的可以參考一下2022-06-06Python實現(xiàn)學生管理系統(tǒng)的示例代碼
學生管理系統(tǒng)是一個常見的應用程序,它可以幫助學校、教育機構(gòu)或教師管理學生的信息,本文將介紹如何利用Python開發(fā)一個學生管理系統(tǒng),需要的可以參考一下2023-07-07全網(wǎng)最全python庫selenium自動化使用詳細教程
這篇文章主要介紹了python庫selenium自動化使用詳細教程,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧2021-01-01Python中Dataframe元素為不定長list時的拆分分組
本文主要介紹了Python中Dataframe元素為不定長list時的拆分分組,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-03-03