I read a text file with several blocks (runs) separated by '\n\n' and am looking for the block with a certain string in the first line. My code:
runinfo=""
with open("./Project/Clean/indexfile.txt") as file:
text=file.read()
runs = text.split('\n\n') #split text into blocks for different runs
for i in range(num_files):
runinfotxt="There is no information to run_id "+Run_ids[i]+" in the indexfile"
for block in runs: #search block with corresponding run_id
firstline=""
for let in block:
firstline=firstline+let
if let=="\n":
break
print("FIRSTLINE: ",firstline)
if firstline ==("run_id: "+Run_ids[i]+"\n"):
runinfotxt=block
runinfo=runinfo+block
else:
pass
The problem: not the complete file is processed. 'text' includes the whole file. But when printing the length of the list 'runs' it returns 74, although my file has much more blocks.
Finding the correct block works well if it is within these first 74 blocks. Is there some kind of size limit that I am running into? I get no error messages. It just behaves as if the file was much shorter.
Edit: The number of items in 'runs' depends on the file that is read. I added some (about 15) blocks to the file and now the length of 'runs' is 94.