我有一个大的日志有几个命令(结尾)和它们的输出(至END)像下面这样:Python的日志分析器
<blabla;
foo
...
...
END
<xyz;
...
...
END
--and so on
的要求是与命令名称不同的文件中像
blabla
xyz
并且在每个文件中应该是它们各自的输出。
到目前为止,我有:
def generateDicts(log_fh):
currentDict = {}
for line in log_fh:
if line.endswith(";"):
if line.endswith("END"):
yield currentDict
currentDict = {""}
else:
currentDict["text"] += line
yield currentDict
with open("logfile.txt") as f:
print list(generateDicts(f))
请帮助。
1)你的问题是什么? 2)你的解决方案有什么不足?它是否打印错误?它是否无法正确执行? –