import re filepath = "01.train_ODC.py" with open(filepath, 'r', encoding='utf-8') as f: content = f.read() # Find the run_cell_magic line pattern = re.compile(r"get_ipython\(\)\.run_cell_magic\('time', '', '(# 🤖 LAND USE CLASSIFICATION MODEL TRAINING.*?)(?=\n')\n'", re.DOTALL) def repl(match): # Get the inner string and escape all actual newlines with \n inner = match.group(1) inner = inner.replace('\n', '\\n') return f"get_ipython().run_cell_magic('time', '', '{inner}')" content = pattern.sub(repl, content) with open(filepath, 'w', encoding='utf-8') as f: f.write(content) print("Fixed 01.train_ODC.py syntax")