Created
October 19, 2018 20:07
-
-
Save PatrikHlobil/9c633b597b2568d3f269c7d5c735974b to your computer and use it in GitHub Desktop.
Delete Output of Jupyter Notebook file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment