【发布时间】:2016-12-16 14:35:30
【问题描述】:
我想将我的结果保存在我的 csv 中。但不知何故,它仍然是空的。但是,如果我不在 csv 中写入相同的输出,而只在 print 中写入,我会得到我想要的结果。
import re
import glob
import os
## is the second script for matchParser.py, match the results for Duration in ms digit
lines = [line.strip() for line in open('output.csv')]
for result in lines:
match = re.search(r'(!?\s.\d[Request completed in\s])', result)
if match: print match.group(0)
但是这个带有 output_csv 的版本不工作,我不知道为什么..
import re
import glob
import os
lines = [line.strip() for line in open('output.csv')]
for result in lines:
match = re.search(r'(!?\s.\d[Request completed in\s])', result)
with open('outputREGEX5.csv', "w") as output_csv:
if match: output_csv.write(match.group(0))
我也收到以下错误:
output.write(match.group(0))
AttributeError: 'NoneType' object has no attribute 'group'
感谢您的帮助。
--
编辑
我的print 输出:
44
37
53
35
17
35
25
27
50
31
27
36
17
66
46
41
38
23
33
【问题讨论】:
标签: python regex python-2.7 python-3.x csv