我有以下文件解析:如何正確拆分下面的字符串? - Python的
Total Virtual Clients : 10 (1 Machines)
Current Connections : 10
Total Elapsed Time : 50 Secs (0 Hrs,0 Mins,50 Secs)
Total Requests : 337827 ( 6687/Sec)
Total Responses : 337830 ( 6687/Sec)
Total Bytes : 990388848 ( 20571 KB/Sec)
Total Success Connections : 3346 ( 66/Sec)
Total Connect Errors : 0 ( 0/Sec)
Total Socket Errors : 0 ( 0/Sec)
Total I/O Errors : 0 ( 0/Sec)
Total 200 OK : 33864 ( 718/Sec)
Total 30X Redirect : 0 ( 0/Sec)
Total 304 Not Modified : 0 ( 0/Sec)
Total 404 Not Found : 303966 ( 5969/Sec)
Total 500 Server Error : 0 ( 0/Sec)
Total Bad Status : 303966 ( 5969/Sec)
,所以我必須解析算法來搜索文件的值,但是,當我這樣做:
for data in temp:
line = data.strip().split()
print line
其中temp
是我的臨時緩衝區,它包含這些值, 我得到:
['Total', 'I/O', 'Errors', ':', '0', '(', '0/Sec)']
['Total', '200', 'OK', ':', '69807', '(', '864/Sec)']
['Total', '30X', 'Redirect', ':', '0', '(', '0/Sec)']
['Total', '304', 'Not', 'Modified', ':', '0', '(', '0/Sec)']
['Total', '404', 'Not', 'Found', ':', '420953', '(', '5289/Sec)']
['Total', '500', 'Server', 'Error', ':', '0', '(', '0/Sec)']
,我想:
['Total I/O Errors', '0', '0']
['Total 200 OK', '69807', '864']
['Total 30X Redirect', '0', '0']
等等。 我怎麼能做到這一點?
這是個酷男!謝謝! (將在幾個接受你的答案) – cybertextron 2013-02-21 22:59:40