import re # ── FIX 1: report_generator.py ────────────────────────────────────────── path1 = r'C:\ALVARO_PROJECTS\Applications\MarineMaintenance\report_generator.py' with open(path1, 'r', encoding='utf-8') as f: src = f.read() old = 'def photo_section(photo_list, label):\n if not photo_list: return' new = 'def photo_section(photo_list, label):\n nonlocal story\n if not photo_list: return' if old in src: src = re.sub(old, new, src) # Use re.sub instead of replace for regex replacement with open(path1, 'w', encoding='utf-8') as f: f.write(src) print('FIX 1 OK: nonlocal story added') else: print('FIX 1 SKIP: already applied or not found')