My scenario is this...
From within a Jupyter Notebook (NB) I want to open another NB, so I locate my current working directory by typing:
import os
os.getcwd()
So I get a listing:
Volume in drive C is OSDisk Volume Serial Number is 8AD4-7C2E
Directory of C:\\Users\\rlysak01\\Desktop\\02-PyCoreBootcamp\\03-Object-and-Data Structure Basics\\Core_Language_Explanations
03/04/2019 05:32 PM testfolder 02/23/2019 03:22 PM 66,763 Untitled.ipynb 4 File(s) 117,932 bytes 4 Dir(s) 1,962,647,552 bytes free
Now I want to open the NB named "untitled.ipynb" to see what's in it.
A Google search only finds ways to launch a new server and open a specified NB from within that new server process.
Is there a way to open that notebook without starting a new Jupyter server on my local machine?
When I try
nb_to_open = os.getcwd() + '\\untitled.ipynb'
open(nb_to_open)
I get the following response, but the notebook does not open:
<_io.TextIOWrapper name='C:\\Users\\rlysak01\\Desktop\\02-PyCoreBootcamp\\untitled.ipynb' mode='r' encoding='cp1252'>
What I really want is to put that file information into the current Notebook server process and open it in a new browser window.
I figured out that I can MANUALLY copy the URL from the current notebook's browser address field and add the NB filename to the URL, but this involves a tedious manual step.
If the current URL is this: http://localhost:8888/notebooks/Desktop/02-PyCoreBootcamp/
I can manually hack it to be this:
http://localhost:8888/notebooks/Desktop/02-PyCoreBootcamp/untitled.ipynb
Then I convert the Jupyter code cell to a Markdown cell, execute the Markdown cell and click on the http hyperlink in the markdown cell.
But this is a manual hack that I want to do complete via Python in the Jupyter NB cell.
If I can find the URL programmatically, then I could add my filename onto the end of the URL.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.