iPython笔记本没有加载:输出太多

Ale*_*ont 5 ipython ipython-notebook

我有一个没有加载的iPython笔记本文件,大概是因为文件中有太多的输出(打印了数千行结果,旧计算机).

我可以使用记事本编辑文件而不会出现问题,但是复制然后逐个单元地清理代码非常耗时.

有没有办法以不同方式恢复代码,或者要求iPython笔记本只加载代码而不打开文件时打印所有过去的输出?

hui*_*hen 4

这是我在Github上找到的输出删除脚本。致谢作者。

      import sys
      import io
      from IPython.nbformat import current


      def remove_outputs(nb):
          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')
Run Code Online (Sandbox Code Playgroud)