Skip to content

Instantly share code, notes, and snippets.

@prideloki
Forked from anonymous/jupyter-notebook-1.py
Last active July 10, 2017 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prideloki/ae27e1bb8e6c2631ccbeba0c454d132a to your computer and use it in GitHub Desktop.
Save prideloki/ae27e1bb8e6c2631ccbeba0c454d132a to your computer and use it in GitHub Desktop.
c = get_config()
### If you want to auto-save .html and .py versions of your notebook:
# modified from: https://github.com/ipython/ipython/issues/8009
import os
from subprocess import check_call
def post_save(model, os_path, contents_manager):
"""post-save hook for converting notebooks to .py scripts"""
if model['type'] != 'notebook':
return # only do this for notebooks
d, fname = os.path.split(os_path)
check_call(['jupyter', 'nbconvert', '--to', 'script', fname], cwd=d)
check_call(['jupyter', 'nbconvert', '--to', 'html', fname], cwd=d)
c.FileContentsManager.post_save_hook = post_save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment