diff options
author | jaseg <git@jaseg.de> | 2025-07-26 17:53:39 +0200 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2025-07-26 17:53:39 +0200 |
commit | eefa5cbb554017a41095e54e6c39592bc1de1761 (patch) | |
tree | 2f2ff3ffe57b1b3a3c11560b3ee79b1480efa4e7 /content/blog/jupyterlab-notebook-file-oneliner | |
parent | 3fd0c107e02858843314107afbbeaf5c056f785f (diff) | |
parent | ccd6338503549e61b74b51c2904617edbfd604cc (diff) | |
download | blog-eefa5cbb554017a41095e54e6c39592bc1de1761.tar.gz blog-eefa5cbb554017a41095e54e6c39592bc1de1761.tar.bz2 blog-eefa5cbb554017a41095e54e6c39592bc1de1761.zip |
deploy.py auto-commitdeploy
Diffstat (limited to 'content/blog/jupyterlab-notebook-file-oneliner')
-rw-r--r-- | content/blog/jupyterlab-notebook-file-oneliner/index.rst | 21 |
1 files changed, 0 insertions, 21 deletions
diff --git a/content/blog/jupyterlab-notebook-file-oneliner/index.rst b/content/blog/jupyterlab-notebook-file-oneliner/index.rst deleted file mode 100644 index 5a543de..0000000 --- a/content/blog/jupyterlab-notebook-file-oneliner/index.rst +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: "Getting the .ipynb Notebook File Location From a Running Jupyter Lab Notebook" -date: 2025-06-29T23:42:00+01:00 -summary: > - If you need to get the path of the ipynb file in a running #Jupyter notebook, this one-liner will do the trick. It - seems chatgpt is confused, and a bunch of other approaches on the web look fragile and/or unnecessarily complex to - me. ---- - -If you need to get the path of the ipynb file in a running #Jupyter notebook, this one-liner will do the trick. It seems -chatgpt is confused, and a bunch of other approaches on the web look fragile and/or unnecessarily complex to me. - -.. code:: python - - import sys - Path(json.loads(Path(sys.argv[-1]).read_bytes())['jupyter_session']) - -The way this works is that for each notebook, jupyter starts a python "kernel" process that actually runs the notebook's -code. That kernel gets a json file with info on the notebook's location on the disk passed through its command line. -Since we're running code in that exact python process, we can just grab that json file from sys.argv, and read it -ourselves. |