Often my notebooks are organized with respect to GITROOT, so this snippet makes for an easy way to construct relative paths.

1gitroot = Path(subprocess.run(["git", "rev-parse", "--show-toplevel"],
2                         check=True,
3                         capture_output=True).stdout.decode("utf-8").strip())
4# Usage
5exdata = gitroot / "data" / "very_important_folder"

For packages which demand string only paths, another helper can be used in tandem.

1def getstrform(pathobj):
2    return str(pathobj.absolute())

Along with a context manager for running commands in a particular directory (kanged from my f2py utilities):

1@contextlib.contextmanager
2def switchdir(path):
3    curpath = Path.cwd()
4    os.chdir(path)
5    try:
6        yield
7    finally:
8        os.chdir(curpath)