Guest User

Untitled

a guest
Oct 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import json
  2. import os
  3.  
  4. #Define path of Jupyter notebook File:
  5. notebook_path = r"c:\Users\Pat\Test.ipynb"
  6.  
  7. #Read in notebook as JSON and delete all output cells:
  8. with open(notebook_path, "r") as f:
  9. nb = json.load(f)
  10. for i, cell in enumerate(nb["cells"]):
  11. if "outputs" in nb["cells"][i]:
  12. nb["cells"][i]["outputs"] = []
  13.  
  14. #Write new jupyter notebook file without output cells
  15. output_path = os.path.join(os.path.splitext(notebook_path)[0] \
  16. + "_no_output.ipynb")
  17. with open(output_path, "w") as f:
  18. json.dump(nb, f, indent=4)
Add Comment
Please, Sign In to add comment