Skip to content

Instantly share code, notes, and snippets.

@K-7
Forked from minrk/remove_output.py
Created September 16, 2021 13:16
Show Gist options
  • Select an option

  • Save K-7/99b784dd996539ff90ce743ed5523d92 to your computer and use it in GitHub Desktop.

Select an option

Save K-7/99b784dd996539ff90ce743ed5523d92 to your computer and use it in GitHub Desktop.
"""
usage: python remove_output.py notebook.ipynb [ > without_output.ipynb ]
"""
import sys
import io
from IPython.nbformat import current
def remove_outputs(nb):
"""remove the outputs from a notebook"""
for ws in nb.worksheets:
for cell in ws.cells:
if cell.cell_type == 'code':
cell.outputs = []
if __name__ == '__main__':
fname = sys.argv[1]
with io.open(fname, 'r') as f:
nb = current.read(f, 'json')
remove_outputs(nb)
print current.writes(nb, 'json')
@K-7
Copy link
Author

K-7 commented Sep 16, 2021

Script to delete all outputs from Jupyter Notebook using python script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment