Here it may be easier to write an regex.
Also bye using
Also bye using
compile
and finditer
make it efficient for larger files.pattern = re.compile(r"\[DOSIMETRY_TOTAL.*\]\s+(\S+)") for match in pattern.finditer(data): print(20 * '-') print(match.group(0))
Output:[DOSIMETRY_TOTAL_DOSE_B: 00]
9.30988
--------------------
[DOSIMETRY_TOTAL_DOSE_E: 00]
8.45142
--------------------
[DOSIMETRY_TOTAL_DOSE_B: 01]
9.18214
--------------------
[DOSIMETRY_TOTAL_DOSE_E: 01]
8.41000
--------------------
[DOSIMETRY_TOTAL_DOSE_B: 02]
8.87531
--------------------
[DOSIMETRY_TOTAL_DOSE_E: 02]
8.35574
.....
data
that i test with is just string of the whole file.group(1)
will be values only.Output:9.30988
--------------------
8.45142
--------------------
9.18214
--------------------
8.41000
--------------------
8.87531
--------------------
8.35574
--------------------
9.15688
--------------------
8.40126
--------------------
8.88971
--------------------
8.48842
.....