Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import os
- #Define path of Jupyter notebook File:
- notebook_path = r"c:\Users\Pat\Test.ipynb"
- #Read in notebook as JSON and delete all output cells:
- with open(notebook_path, "r") as f:
- nb = json.load(f)
- for i, cell in enumerate(nb["cells"]):
- if "outputs" in nb["cells"][i]:
- nb["cells"][i]["outputs"] = []
- #Write new jupyter notebook file without output cells
- output_path = os.path.join(os.path.splitext(notebook_path)[0] \
- + "_no_output.ipynb")
- with open(output_path, "w") as f:
- json.dump(nb, f, indent=4)
Add Comment
Please, Sign In to add comment