23 lines
687 B
Python
23 lines
687 B
Python
import json
|
|
import os
|
|
from pathlib import Path
|
|
|
|
def extractToFiles(filePath: str, folder: str = "extracted_cells"):
|
|
with open(filePath, "r") as file:
|
|
fileContent = file.read()
|
|
content = json.loads(fileContent)
|
|
i=0
|
|
for cell in content["cells"]:
|
|
if cell["cell_type"] == "code":
|
|
codeStr = ""
|
|
for line in cell["source"]:
|
|
codeStr += line
|
|
Path(folder).mkdir(parents=True, exist_ok=True)
|
|
location = os.path.join(folder, f"cell{i}.py")
|
|
with open(location, "w+") as file:
|
|
file.write(codeStr)
|
|
i += 1
|
|
|
|
|
|
extractToFiles("Explainable_AI_Adult_Census_Income.ipynb")
|