Skip to content

Instantly share code, notes, and snippets.

@jaseg
Created June 30, 2025 10:25
Show Gist options
  • Select an option

  • Save jaseg/5107970f32f98f3b35d54e2aa4be0246 to your computer and use it in GitHub Desktop.

Select an option

Save jaseg/5107970f32f98f3b35d54e2aa4be0246 to your computer and use it in GitHub Desktop.

Revisions

  1. jaseg created this gist Jun 30, 2025.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    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.
    2 changes: 2 additions & 0 deletions oneliner.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    import sys
    Path(json.loads(Path(sys.argv[-1]).read_bytes())['jupyter_session'])