Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. # This file has to be saved in your Jupyter config directory (found by running
  2. # jupyter --config-dir
  3. # but usually C:\Users\<username>\.jupyter\jupyter_notebook_config.py on Windows
  4.  
  5. def scrub_output_pre_save(model, **kwargs):
  6. """scrub output before saving notebooks"""
  7. # only run on notebooks
  8. if model['type'] != 'notebook':
  9. return
  10. # only run on nbformat v4
  11. if model['content']['nbformat'] != 4:
  12. return
  13.  
  14. for cell in model['content']['cells']:
  15. if cell['cell_type'] != 'code':
  16. continue
  17. cell['outputs'] = []
  18. cell['execution_count'] = None
  19. if 'collapsed' in cell['metadata']:
  20. cell['metadata'].pop('collapsed', 0)
  21.  
  22. c.FileContentsManager.pre_save_hook = scrub_output_pre_save
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement