擅长:python、mysql、java
<p>创建生成器(当前生成器折弯上的Im)</p>
<pre><code>def generateDicts(log_fh):
currentDict = {}
for line in log_fh:
if line.startswith("2015"): #you might want a better check here
if currentDict:
yield currentDict
currentDict = {"date":line.split("-")[0],"type":line.split("-")[2],"text":line.split("-")[-1]}
else:
currentDict["text"] += line
yield currentDict
with open("logfile.txt") as f:
print list(generateDicts(f))
</code></pre>
<p>可能有一些小错误。。。我并没有真的运行这个</p>