Skip to content

Instantly share code, notes, and snippets.

@ayoskovich
Created August 30, 2020 02:08
Show Gist options
  • Save ayoskovich/e1af9db79a25ab0a4de7b5d4f98150e5 to your computer and use it in GitHub Desktop.
Save ayoskovich/e1af9db79a25ab0a4de7b5d4f98150e5 to your computer and use it in GitHub Desktop.
Add this to jupyter_notebook_config.py in order to auto remove cell numbers and output from jupyter notebooks.
def scrub_output_pre_save(model, **kwargs):
"""scrub output before saving notebooks"""
# only run on notebooks
if model['type'] != 'notebook':
return
# only run on nbformat v4
if model['content']['nbformat'] != 4:
return
for cell in model['content']['cells']:
if cell['cell_type'] != 'code':
continue
cell['outputs'] = []
cell['execution_count'] = None
c.FileContentsManager.pre_save_hook = scrub_output_pre_save
@ayoskovich
Copy link
Author

ayoskovich commented Aug 30, 2020

To show config directory:
$ jupyter --config-dir

To create a config file if one doesn't already exist:
$ jupyter notebook --generate-config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment