gpt4 book ai didi

python - 我将如何解析以下日志?

转载 作者:行者123 更新时间:2023-11-28 19:41:21 25 4
gpt4 key购买 nike

我需要解析如下格式的日志:

===== Item 5483/14800  =====
This is the item title
Info: some note
===== Item 5483/14800 (Update 1/3) =====
This is the item title
Info: some other note
===== Item 5483/14800 (Update 2/3) =====
This is the item title
Info: some more notes
===== Item 5483/14800 (Update 3/3) =====
This is the item title
Info: some other note
Test finished. Result Foo. Time 12 secunds.
Stats: CPU 0.5 MEM 5.3
===== Item 5484/14800 =====
This is this items title
Info: some note
Test finished. Result Bar. Time 4 secunds.
Stats: CPU 0.9 MEM 4.7
===== Item 5485/14800 =====
This is the title of this item
Info: some note
Test finished. Result FooBar. Time 7 secunds.
Stats: CPU 2.5 MEM 2.8

我只需要提取每个项目的标题(===== Item 5484/14800 之后的下一行 =====)和结果。
所以我只需要保留包含项目标题和该标题的结果的行,并丢弃其他所有内容。
问题是有时一个项目有注释(最多 3 个),有时显示的结果没有额外的注释,所以这很棘手。
任何帮助,将不胜感激。我在 python 中做解析器,但不需要实际代码,但有些人指出我如何实现这个?

LE:我正在寻找的结果是丢弃所有其他东西并得到类似的东西:

('This is the item title','Foo')
then
('This is this items title','Bar')

最佳答案

1) Loop through every line in the log

a)If line matches appropriate Regex:

Display/Store Next Line as the item title.
Look for the next line containing "Result
XXXX." and parse out that result for
including in the result set.

编辑:现在我看到了您正在寻找的结果,添加了更多内容。

关于python - 我将如何解析以下日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/977458/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com