SKIP阅读行,如果下一行有特定的字符串

问题描述 投票:0回答:1
我有一个大文件,其中有很多时序信息。摘录看起来像

CPU time for df vj and vk 329.45135 sec, wall time 10.42650 sec CPU time for df vj and vk 331.06361 sec, wall time 10.48211 sec CPU time for df vj and vk 330.34512 sec, wall time 10.45198 sec CPU time for df vj and vk 330.43818 sec, wall time 10.46212 sec CPU time for orbital rotation 1341.99499 sec, wall time 42.54674 sec CPU time for update CAS DM 12.02945 sec, wall time 0.37361 sec CPU time for micro iter 1 0.00003 sec, wall time 0.00003 sec CPU time for density fitting ao2mo pass1 157.41450 sec, wall time 19.02017 sec CPU time for density fitting papa pass2 11.19426 sec, wall time 0.61816 sec CPU time for density fitting ppaa pass2 24.55801 sec, wall time 6.68668 sec CPU time for df vj and vk 171.32896 sec, wall time 5.41600 sec CPU time for density fitting ao2mo 366.81797 sec, wall time 33.65705 sec CPU time for update eri 366.82145 sec, wall time 33.66198 sec CPU time for integral transformation to CAS space 0.00001 sec, wall time 0.00000 sec
在其他几个参数中,必须计算所有
df vj and vk

density fitting ao2mo  
的总和。我的核心功能是
total+=sum([float(line.split()[position]) for line in open(file_name).readlines() if parameter in line])

position

file_name
取决于我是要获得CPU时间还是墙时间,
parameter
是存储文本的文件,而
df vj and vk
是我试图收集数据的函数。

我获得47.23871的

density fitting ao2mo

,为33.65705 for
density fitting ao2mo
.
问题如下 -

df vkj and vk

包含上方的时间(5.41600秒线)。我希望

df vj and vk
排除直接紧随其后的线,其中包含
density fitting ao2mo  
。 因此,我希望结果为41.82271。我该怎么做?
    
i通过检查下一行是否有要排除的参数来解决此问题。

列表理解方法看起来像

df vj and vk

python-3.x
1个回答
0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.