Jupyter equivalent of sys.path[0] (how to get the directory of the notebook file)

In Jupyter,

jupyter_syspath_example.py
import sys
sys.path[0]

will not return the directory where the notebook file resides but something like

example.txt
/usr/lib/python310.zip

Instead, use

example.py
import os.path

os.path.dirname(os.path.realpath("__file__"))

Check out similar posts by category: Jupyter, Python