Created
September 14, 2012 04:45
-
-
Save minrk/3719849 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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') |
Another thing that I can't crack is how can I remove the whole cell. I tried something like this:
if 'skip' in cell.metadata.slideshow.slide_type:
cell = None
but that does not work :-(
A script like this for newer versions can be found at:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
purge only binary display blobs, and renumber prompts
to eliminate diff noise. more invasive.