For Python (ipykernel) in Jupyter, we have the magic command %run ./some_notebook.ipynb
to run another notebook (e.g. effectively "importing" functions from another notebook).
Can you do the same thing with javascript running Deno kernel in Jupyter?
%run
doesn't seem to work with Deno kernel.
There is a Deno.run
method, but I can't figure out if this is the purpose of the method or what the syntax would be (via Google, trying to track it down in Deno codebase, etc).
For example, Deno.run('./some_notebook.ipynb')
yields
Stack trace:
TypeError: Cannot read properties of undefined (reading '0')
at Object.run (ext:deno_process/40_process.js:143:10)
at <anonymous>:3:6
Does anyone know if this is possible? Thanks
(Sorry, I'm actually using jupyterlab, but I just tested and it's the same way in jupyter notebook)
====================
Edit to add a couple more things tried:
I realized I could just parse and eval the contents of the notebook (could be a big security risk, but I'm just using this as a tool for my early and local development), and this does evaluate the commands from the notebook, but the functions/variables aren't available in other cells (maybe intentional based on security threat). I couldn't find anything like a Deno.eval to get around this.
let notebookContent = await Deno.readTextFile('./TestImportDenoNotebook.ipynb')
let notebookJSON = JSON.parse(notebookContent);
for (const cell of notebookJSON.cells) {
const cellSource = cell.source.join('\n');
new Function(cellSource)();
}
Also, I found the syntax for Command (run in Jupyter), and it seems to run the notebook, but probably in a separate process (I still don't have access to the functions/variables from the other notebook):
let filename = './TestImportDenoNotebook.ipynb';
const command = new Deno.Command("jupyter", {
args: ["execute", "--kernel_name=deno", filename],
});
const { code, stderr } = await command.output();
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744251468a4565187.html
评论列表(0条)