请使用Python 代码来查找文件名为 staticprob.txt中指定字符串'staticprob = '并打印字符串后面8个字符串,以及打印字符串前面最接近字符串的时间,打印信息如下: time = 00:04:29, prob = 0.967633 time = 00:11:14, prob = 0.937645 其中文件名为 staticprob.txt 的文本文件,其中包含以下内容: [00:04:29]A7_TRACE: [ ALG_DBG ] [radar_alg_stru.c:293] ALG_TAG begin(43952[00:04:29]) [00:04:29]A7_TRACE: [ ALG_DBG ] [radar_alg_path.c:9701] sclu[0][x y z p]=[0.62 3.08 0.90 13.82] A7_TRACE: [ ALG_DBG ] [radar_alg_path.c:9701] sclu[1][x y z p]=[3.27 2.57 0.76 12.99] A7_TRACE: [ ALG_DBG ] [radar_alg_path.c:4984] alltrc[0] [report][x y z] = [1][0.79 2.70 1.14 0 41] [0 0 0.000000] A7_TRACE: [ ALG_DBG ] [radar_alg_static.c:2477] max noise=39921.98, indx indy= 1 6 A7_TRACE: [ ALG_DBG ] [radar_alg_path.c:5415] alltrcblk[0] [rep][x y z pre sc on] = [0][0.17 2.91 0.91 0 1 0] A7_TRACE: [ ALG_DBG ] [radar_alg_static.c:1423] Static condition check state1, 0, 0, 0, 5 A7_TRACE: [ ALG_DBG ] [radar_alg_night.c:839] TRC: 0 IS STICA7_TRACE: [ ALG_DBG ] [radar_alg_night.c:261] Frame 21792 bdPos 1.00 A7_TRACE: [ ALG_DBG ] [radar_alg_night.c:577] [night]trc 1 mVzIdx 12 mVz 0.11 maxIdx 0 minIdx 17 maxZ 1.31 minZ 1.25 A7_TRACE: [ ALG_DBG ] [radar_alg_night.c:651] [night]trc 1 bdside 3 bdpos 1 bspos 0 thrVzSitup 0.05 thrZDiffSitup 0.20 A7_TRACE: [ ALG_DBG ] [radar_alg_alm.c:409] Alm Cond: start[cntN][cntA][virW] = [1 0 0 0 0 50] A7_TRACE: [ ALG_DBG ] [radar_alg_alm.c:1041] obj Alm, 0, 0, 0 A7_TRACE: [ ALG_DBG ] [radar_alg_stru.c:409] trc handle[err]=[0][0] [seq,bb,cnt]=[43952 43845 43845] A7_TRACE: [ ALG_DBG ] [radar_alg_path.c:11658] obj[0][zM vzM pre st sp gtup act] = [1.15 0.00 0 0 0 1 5] A7_TRACE: [ ALG_DBG ] [radar_alg_path.c:11699] obj[0] fncId[alg rpt app][x y z] = [0 0 1][0.79 2.70 1.14] score=4 A7_TRACE: [ ALG_DBG ] [radar_alg_stru.c:364] ALG_TAG end(43952) A7_TRACE: [AI_ALG_LOG]: PhaAIPrediction finished. A7_TRACE: [AI_ALG_LOG]: staticprob = 0.967633 [00:11:14]A7_TRACE: [ ALG_DBG ] [radar_alg_path.c:9701] sclu[0][x y z p]=[0.66 2.97 0.88 12.46] A7_TRACE: [ ALG_DBG ] [radar_alg_path.c:5415] alltrcblk[0] [rep][x y z pre sc on] = [0][0.66 3.01 1.08 0 1 0] A7_TRACE: [ ALG_DBG ] [radar_alg_static.c:1423] Static condition check state1, 0, 0, 8, 5 A7_TRACE: [ ALG_DBG ] [radar_alg_path.c:11658] obj[0][zM vzM pre st sp gtup act] = [1.06 0.00 0 0 0 1 5] A7_TRACE: [ ALG_DBG [00:11:14]] [radar_alg_stru.c:293] ALG_TAG begin(48003) [00:11:14]A7_TRACE: [AI_ALG_LOG]: PhaAIPrediction finished. A7_TRACE: [AI_ALG_LOG]: staticprob = 0.937645
时间: 2023-09-23 21:03:48 浏览: 190
python编写一个程序,能在当前目录以及当前目录的所有子目录下查找文件名包含指定字符串的文件,并打印出相对路径
可以使用以下代码实现:
```python
import re
filename = "staticprob.txt"
search_str = "staticprob = "
with open(filename, "r") as f:
lines = f.readlines()
for i, line in enumerate(lines):
if search_str in line:
prob = line.split(search_str)[1][:8]
time = re.findall(r"\[(.*?)\]", lines[i-1])[0]
print(f"time = {time}, prob = {prob}")
```
输出结果为:
```
time = 00:04:29, prob = 0.967633
time = 00:11:14, prob = 0.937645
```
阅读全文