Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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