Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 39561
1
# Based on See https://gist.github.com/damianavila/5305869
2
3
import sys, io, os
4
from nbformat.v4 import reads, writes
5
6
def remove_outputs(nb):
7
"""
8
Remove the outputs from a notebook.
9
"""
10
for cell in nb.cells:
11
if cell.cell_type == 'code':
12
cell.outputs = []
13
14
def main():
15
for fname in sys.argv[1:]:
16
nb = reads(io.open(fname, 'r').read())
17
remove_outputs(nb)
18
base, ext = os.path.splitext(fname)
19
new_ipynb = "%s-no-output%s" % (base, ext)
20
io.open(new_ipynb, 'w', encoding='utf8').write(writes(nb))
21
22
if __name__ == "__main__":
23
main()
24