我的文本文件的行如下。这种类型的行在文件中多次出现。需要从Python的括号内的文本文件中读取数据
[年11月22 22点27分13秒] INFO - [com.macys.seo.business.impl.LinkBusinessImpl] - 执行搜索(WS)网关请求:KeywordVO(关键字= GUESS得分= 83965 normalizedKeyword = GUESS productIds = [] categoryIds = [] hotListed =假列入黑名单=假globalHotList =假URL = /购买/猜测)
我想仅在以下数据中提取到一个文件,如:
关键字=猜测,分数= 83965,hotListed = false,globalHotList = false url =/buy/GUESS
这是我到目前为止有:
def get_sentences(filename):
with open('d:\log.log') as file_contents:
d1, d2 = '(', ')' # just example delimiters
for line in file_contents:
if d1 in line:
results = []
elif d2 in line:
yield results
else: results.append(line)
print results
请指教。
解决方案是否必须是Python的?你坚持哪部分? – Johnsyweb
我只需要使用python。我的代码段是def get_sentences(filename): with open('d:\ log.log')as file_contents: d1,d2 ='(',')'#只是示例分隔符 for file in file_contents: if D1在行: 结果= [] ELIF D2在行: 收效 其他: results.append(线) 打印效果 – newcane