Last active
September 21, 2023 04:50
-
-
Save jbwhit/881bdeeaae3e4128947c to your computer and use it in GitHub Desktop.
Saves Jupyter Notebooks as .py and .html files automatically. Add to the ipython_notebook_config.py file of your associated profile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from subprocess import check_call | |
def post_save(model, os_path, contents_manager): | |
"""post-save hook for converting notebooks to .py and .html files.""" | |
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
So it looks like this stackoverflow answer has the right way to go about this: https://stackoverflow.com/questions/29329667/ipython-notebook-script-deprecated-how-to-replace-with-post-save-hook
and it will output the file name:
And that's the location that you'd like to edit. I've also tweaked the call to use
jupyter
instead ofipython
.