How to Get Path of Current Notebook

In an earlier post, we saw how to get the absolute path of a notebook in Azure Databricks by navigating GUI in the workspace. In this post, let us see how we can get the same programmatically –

If Scala is your preferred language then it’s pretty straightforward as shown below –

You can store this value in a variable too if you need to use it further in your program.

However, if python is your mainstream language then it’s not that easy. You still need to get it using Scala but in order to switch back to you python language in another cell and thinking to consume the path which was read using Scala, you need to save it somewhere like in a widget and then read it from the widget as shown below –

current notebook path read using Scala and saved in the widget named notebook
reading the path from widget using python

As widget was a temporary placeholder for notebook path so it was removed immediately after reading its value.