Path: blob/master/src/smc_pyutil/smc_pyutil/jupyter_delete_output.py
Views: 285
# -*- coding: utf-8 -*-12# This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.3# License: AGPLv3 s.t. "Commons Clause" – read LICENSE.md for details45# Based on See https://gist.github.com/damianavila/530586967from __future__ import absolute_import8import sys, io, os9from nbformat.v4 import reads, writes101112def remove_outputs(nb):13"""14Remove the outputs from a notebook.15"""16for cell in nb.cells:17if cell.cell_type == 'code':18cell.outputs = []192021def main():22for fname in sys.argv[1:]:23nb = reads(io.open(fname, 'r').read())24remove_outputs(nb)25base, ext = os.path.splitext(fname)26new_ipynb = "%s-no-output%s" % (base, ext)27io.open(new_ipynb, 'w', encoding='utf8').write(writes(nb))282930if __name__ == "__main__":31main()323334