From cfd24fbd92e4e85f7a2a64386c401c91fa9f7baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dami=C3=A1n=20Avila?= Date: Wed, 3 Apr 2013 22:05:06 +0000 Subject: [PATCH] --- remove_output.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 remove_output.py diff --git a/remove_output.py b/remove_output.py new file mode 100644 index 0000000..3fc2ea9 --- /dev/null +++ b/remove_output.py @@ -0,0 +1,28 @@ +""" +Usage: python remove_output.py notebook.ipynb [ > without_output.ipynb ] +Modified from remove_output by Minrk + +""" +import sys +import io +import os +from IPython.nbformat.current import read, write + + +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 = read(f, 'json') + remove_outputs(nb) + base, ext = os.path.splitext(fname) + new_ipynb = "%s_removed%s" % (base, ext) + with io.open(new_ipynb, 'w', encoding='utf8') as f: + write(nb, f, 'json') + print "wrote %s" % new_ipynb \ No newline at end of file