21 lines
743 B
Python
21 lines
743 B
Python
import json
|
|
|
|
def fix_import(file_path):
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|
nb = json.load(f)
|
|
changed = False
|
|
for cell in nb.get('cells', []):
|
|
if cell.get('cell_type') == 'code':
|
|
source = cell.get('source', [])
|
|
if isinstance(source, list):
|
|
for i, line in enumerate(source):
|
|
if "from new_import import *" in line:
|
|
source[i] = line.replace("from new_import import *", "from new_import_ODC import *")
|
|
changed = True
|
|
if changed:
|
|
with open(file_path, 'w', encoding='utf-8') as f:
|
|
json.dump(nb, f, indent=1)
|
|
print(f"Fixed {file_path}")
|
|
|
|
fix_import('new_train.ipynb')
|