lines=open('GAUGE/L4GAUGE.CFG',encoding='latin-1').read().split('\n') # MechInit block extent from 4390 depth=0; opened=False; close=None for i in range(4390,len(lines)+1): l=lines[i-1] for ch in l: if ch=='{': depth+=1; opened=True elif ch=='}': depth-=1 if opened and depth==0: close=i; break print("MechInit block: 4390 ..", close, "| prepEngr@4595 inside:", 4390<=4595<=(close or 0)) # structure between 4407 and 4600 print("--- lines 4408-4430 & around 4590-4600 ---") for i in list(range(4408,4416))+list(range(4590,4600)): print(f" {i}: {lines[i-1].strip()[:70]}") # any nested braces / sub-blocks between 4407 and 4595? d=0 for i in range(4390,4600): for ch in lines[i-1]: if ch=='{': d+=1 elif ch=='}': d-=1 if lines[i-1].strip().endswith('{') or lines[i-1].strip()=='}': print(f" brace@{i} depth->{d}: {lines[i-1].strip()[:50]}")