Why is the current path different when executing a Notebook from Repos vs Workspace?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 07:39 AM
When executing the same Notebook from Repos and Workspace, the current path (`os.getcwd()`) is different:
- Repos=/Workspace/Repos/USERID/REPONAME.ide/pricing
- Workspace=/home/spark-1636b562-0ce7-473b-bb17-56
The issue is the Databricks VScode extension recommends switching from Repos to Workspace, but then all the notebook code containing relative path to the notebook doesn't work anymore.
Would it be possible to have Workspace behave the same way as Repos?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 05:14 PM
Found a work around:
``` Python
import os
notebook_dir = os.path.dirname(dbutils.notebook.entry_point.getDbutils().notebook().getContext().notebookPath().get())
notebook_dir = "/Workspace" + notebook_dir
current_dir = os.getcwd()
if current_dir != notebook_dir:
print(f"Switching current dir to: {notebook_dir}")
os.chdir(notebook_dir)
```

