如何使 Jupyter Lab 保存笔记本(以编程方式) [英] How to cause Jupyter Lab to save notebook (programmatically)

查看:28
本文介绍了如何使 Jupyter Lab 保存笔记本(以编程方式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以通宵运行的笔记本,可以打印出一堆东西,包括图像等.我想以编程方式保存此输出(可能以特定时间间隔).我还想保存运行的代码.在 Jupyter 笔记本中,您可以:

I have a notebook that runs overnight, and prints out a bunch of stuff, including images and such. I want to cause this output to be saved programatically (perhaps at certain intervals). I also want to save the code that was run. In a Jupyter notebook, you could do:

from IPython.display import display, Javascript
display(Javascript('IPython.notebook.save_checkpoint();'))
# causes the current .ipynb file to save itself (same as hitting CTRL+s)

(来自 从内部以编程方式保存 IPython 笔记本?)

虽然,我发现这个 javascript 注入在 Jupyter 实验室中不起作用(Jupyter not found).我的问题是如何在 Jupyter 实验室中执行上述代码的等效操作.在检查 jupyter 实验室的 HTML 时,我找不到 Jupyter 对象.

Although, I found that this javascript injection did not work in Jupyter lab(Jupyter not found). My question is how to do the equivalent of the above code in Jupyter lab. Upon inspecting the HTML of the jupyter lab, I could not find the Jupyter object.

推荐答案

您可以使用 ipylab 访问来自 Python 的 JupyterLab API.要保存笔记本,只需调用 docmanager:save 命令:

You can use ipylab to access JupyterLab API from Python. To save the notebook just invoke the docmanager:save command:

from ipylab import JupyterFrontEnd

app = JupyterFrontEnd()
app.commands.execute('docmanager:save')

您可以使用 app.commands.list_commands() 获取完整的命令列表.

You can get the full list of commands with app.commands.list_commands().

这篇关于如何使 Jupyter Lab 保存笔记本(以编程方式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆