In order to view/download the latest notebook via github or nbviewer
or to see how the the notebook code has changed we activate saving the
.py
files automatically and track both .ipynb
files and the .py
files.
In order to automate it, add the following code in the
ipython_notebook_config.py
file:
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(['ipython', 'nbconvert', '--to', 'script', fname], cwd=d)
c.FileContentsManager.post_save_hook = post_save
If you aren't sure in which directory to find your
ipython_notebook_config.py
file, you can type ipython locate profile default
, and if you don't find the file there, you can create
it by typing ipython profile create
.