Skip to content

Instantly share code, notes, and snippets.

@cmoscardi
Created August 24, 2017 15:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cmoscardi/75a4cf2362c49deb36cdd6b991c25786 to your computer and use it in GitHub Desktop.
Save cmoscardi/75a4cf2362c49deb36cdd6b991c25786 to your computer and use it in GitHub Desktop.
Jupyter Notebook Output Cleaning Script
#!/usr/bin/env ipython
import io
import sys
from nbformat import read, write
# Handle either stdin or a filename
if __name__ == '__main__':
for filename in sys.argv[1:]:
ipynb = read(filename, 4)
ipynb.metadata.signature = ''
for cell in ipynb.cells:
if "outputs" in cell:
cell["outputs"] = []
if "execution_count" in cell:
cell["execution_count"] = None
with io.open(filename, mode="w", encoding='utf-8') as fh:
write(ipynb, fh)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment