Is there a way to programmatically save a jupyter notebook before running nbconvert? #13535
Replies: 1 comment 2 replies
-
Greetings @jamsden You can use the jupyter module to programmatically save the current notebook before executing nbconvert. Here's an example of how you could modify your code to use the jupyter module:
This code uses the jupyter_client.manager.KernelManager class to get the kernel ID for the current notebook, and then sends a "save" message to the kernel using the execute() method. This should save the current notebook before executing nbconvert. Note that the os.kill(os.getpid(), 1) line is used to interrupt the kernel after the "save" message has been sent. This is necessary because the kernel will not respond to any further messages until the "save" operation has completed. The os.kill() call sends a SIGUSR1 signal to the current process, which interrupts the kernel and allows the nbconvert command to be executed. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm looking for a way to save a jupyter notebook that is running in vscode before invoking nbconvert to generate an HTML snapshot. I was exploring something like:
But that doesn't work - code has no --command parameter.
Is there some other way to programmatically save the current notebook before executing nbconvert?
Beta Was this translation helpful? Give feedback.
All reactions