python 自动将Jupyter笔记本保存为.py和.html文件。添加到关联配置文件的ipython_notebook_config.py文件中。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 自动将Jupyter笔记本保存为.py和.html文件。添加到关联配置文件的ipython_notebook_config.py文件中。相关的知识,希望对你有一定的参考价值。

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(['ipython', 'nbconvert', '--to', 'script', fname], cwd=d)
    check_call(['ipython', 'nbconvert', '--to', 'html', fname], cwd=d)

c.FileContentsManager.post_save_hook = post_save

以上是关于python 自动将Jupyter笔记本保存为.py和.html文件。添加到关联配置文件的ipython_notebook_config.py文件中。的主要内容,如果未能解决你的问题,请参考以下文章