Skip to content

Instantly share code, notes, and snippets.

@damianavila
Forked from minrk/remove_output.py
Created March 14, 2013 13:57
Show Gist options
  • Save damianavila/5161522 to your computer and use it in GitHub Desktop.
Save damianavila/5161522 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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment