tayaeu.blogg.se

Get file path jupyter
Get file path jupyter











get file path jupyter get file path jupyter
  1. #Get file path jupyter update#
  2. #Get file path jupyter code#

Var command = "NOTEBOOK_FULL_PATH = '" + nb.base_url + nb.notebook_path + "'" To store the NOTEBOOK_FULL_PATH on the current notebook front end: %%javascript Here I'm showing the entire path on the Jupyter server, not just the notebook name: Note that, as also reported by others, the Javascript-based method does not seem to work when executing a "Run all cells" (but works when executing cells "manually"), which was a deal-breaker for me. Pass # There may be stale entries in the runtime directoryĪs stated in the docstring, this works only when either there is no authentication or the authentication is token-based. If srv='' and not srv: # No token and no password, ahem. NOTE: works only when the security is token-based or there is also no passwordĬonnection_file = os.path.basename(ipykernel.get_connection_file()) """Returns the absolute path of the Notebook or None if it cannot be determined If jupyterlab._version_.split(".") = "3":įrom jupyter_server import serverapp as app I checked it on Python v3.6.1 + Notebook v5.0.0 and on Python v3.6.5 and Notebook v5.5.0.

#Get file path jupyter update#

The accepted solution by and the update by appear not to be working with recent versions of the Notebook. It seems I cannot comment, so I have to post this as an answer. Out : HowToGetTheNameOfTheNoteBookSolBisĬontrary to the first solution, modifications of notebook's name are updated immediately and there is no need to refresh the notebook. Then, from a ipython cell, In : print(theNotebook) Var command = "theNotebook = " + "'"+thename+"'" Var thename = ("notebook_name").innerHTML

#Get file path jupyter code#

The code becomes, still using the javascript magic %%javascript It is then possible to catch this value by a document.getElementById() and then follow the same approach as above. Looking into the source, it appears that this field has id "notebook_name". On reflection, a more efficient solution is to look for the input field for notebook's name instead of the tag. Out: HowToGetTheNameOfTheNoteBook.ipynbĪ defect in this solution is that when one changes the title (name) of a notebook, then this name seems to not be updated immediately (there is probably some kind of cache) and it is necessary to reload the notebook to get access to the new name. Var command = "theNotebook = " + "'"+attribs.value+"'" įrom a Python code cell print(theNotebook) Since this last variable is known from the kernel, it can be accessed in other cells as well. Then it is possible to access to the Javascript variable through a call to the Python Kernel, with a command which sets a Python variable. Thus the idea is first to ask Javascript to retrieve the attribute -javascripts can be invoked from a codecell thanks to the %%javascript magic. # Updated answer with semi-solutions for both IPython 2.x and IPython tag of the page. It's a flaming hack though so don't rely on this at all: import jsonĬonnection_file_path = kernel.get_connection_file()Ĭonnection_file = os.path.basename(connection_file_path) As already mentioned you probably aren't really supposed to be able to do this, but I did find a way.













Get file path jupyter