Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

R

Views: 4031
1
#!/usr/local/bin/sage -python
2
"""
3
Usage: python remove_output.py notebook.ipynb [ > without_output.ipynb ]
4
Modified from remove_output by Minrk
5
"""
6
import sys
7
import io
8
import os
9
from IPython.nbformat.current import read, write
10
11
12
def remove_outputs(nb):
13
"""remove the outputs from a notebook"""
14
for ws in nb.worksheets:
15
for cell in ws.cells:
16
if cell.cell_type == 'code':
17
cell.outputs = []
18
19
if __name__ == '__main__':
20
fname = sys.argv[1]
21
with io.open(fname, 'r') as f:
22
nb = read(f, 'json')
23
remove_outputs(nb)
24
base, ext = os.path.splitext(fname)
25
new_ipynb = "%s_removed%s" % (base, ext)
26
with io.open(new_ipynb, 'w', encoding='utf8') as f:
27
write(nb, f, 'json')
28
print "wrote %s" % new_ipynb
29
30