IPython magic to open a notebook

42 views
Skip to first unread message

John Kitchin

unread,
Oct 9, 2016, 9:43:24 AM10/9/16
to Project Jupyter
Is there an Ipython magic, or python function that would open a notebook?

I know you can do it from a command line, but I want to run a python function that downloads and opens a notebook from an Ipython shell.

I found the %notebook magic, but it seems to convert the current history to a notebook, which is not what I need.

Thanks,

John Kitchin

unread,
Oct 9, 2016, 9:47:35 AM10/9/16
to Project Jupyter
I did manage to do it with something like:

import os
os.system('jupyter notebook example.ipynb')

but it seems like that is not the best approach.

Thomas Kluyver

unread,
Oct 9, 2016, 11:30:27 AM10/9/16
to Project Jupyter
On 9 October 2016 at 14:47, John Kitchin <johnrk...@gmail.com> wrote:
I did manage to do it with something like:

import os
os.system('jupyter notebook example.ipynb')

but it seems like that is not the best approach.

That's more or less the approach I'd use. I'd recommend using the subprocess module rather than os.system, so you can avoid dealing with quoting filenames:

subprocess.Popen(['jupyter', 'notebook', filename])

You could launch the notebook server inside the existing process, but there's no clear advantage to doing so.

Thomas
Reply all
Reply to author
Forward
0 new messages