Skip to content

Instantly share code, notes, and snippets.

@lawlesst
Forked from cmoscardi/clean_nbs.py
Last active May 21, 2020 11:28
Show Gist options
  • Save lawlesst/24665cb91ccee29666cfc41a161bbd50 to your computer and use it in GitHub Desktop.
Save lawlesst/24665cb91ccee29666cfc41a161bbd50 to your computer and use it in GitHub Desktop.
Jupyter Notebook Output Cleaning Script
import io
import sys
from nbformat import read, write
# Handle either stdin or a filename
if __name__ == '__main__':
for filename in sys.argv[1:]:
print(filename, file=sys.stderr)
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
ipynb.metadata.language_info["version"] = 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