The issue you're encountering with dbutils.notebook.entry_point.getDbutils().notebook().getContext().notebookPath().get()
not returning a valid path that can be used in Python is known. This method indeed strips off the /Workspace
from the start of the path and removes the suffix, which causes the Path.exists()
check to fail.
To get the actual path of a notebook, you can prepend /Workspace
to the path returned by getDbutils().notebook().getContext().notebookPath().get()
. Here is an example of how you can modify your code to achieve this:
from pathlib import Path
import os
# Get the notebook path
notebook_path = dbutils.notebook.entry_point.getDbutils().notebook().getContext().notebookPath().get()
# Prepend '/Workspace' to the path
full_notebook_path = '/Workspace' + notebook_path
# Check if the path exists
print(Path(full_notebook_path).exists())