How can I open an IPython notebook without the output?

前端 未结 4 968
感情败类
感情败类 2021-02-01 07:25

I have an IPython notebook where I\'ve accidentally dumped a huge output (15 MB) that crashed the notebook. Now when I open the notebook and attempt to delete the troubleso

4条回答
  •  太阳男子
    2021-02-01 07:54

    If you are running jupyter 4.x, you will get some API deprecation warnings when running filmor's script. Although the script still works, I update the script a bit to remove the warnings.

    #!/usr/bin/env python
    
    def strip_output(nb):
        for cell in nb.cells:
            if hasattr(cell, "outputs"):
                cell.outputs = []
            if hasattr(cell, "prompt_number"):
                del cell["prompt_number"]
    
    
    if __name__ == "__main__":
        from sys import stdin, stdout
        from nbformat import read, write
    
        nb = read(stdin, 4)
        strip_output(nb)
        write(nb, stdout, 4)
        stdout.write("\n")
    

提交回复
热议问题