โ11-17-2021 06:16 AM
Not sure it exists but maybe there is some trick to get directly from python code:
just working on some logger script shared between notebooks and it could make my life a bit easier ๐
โ11-18-2021 08:24 AM
Hi @Hubert Dudekโ ,
The following command will print the path where your notebook is located. If you split the returned string and only select the last string, then you will be able to get the notebook name
notebook_name = dbutils.notebook.entry_point.getDbutils().notebook().getContext().notebookPath().get()
โ11-17-2021 11:57 AM
Hey there! Thanks for your question. We'll see what the community comes up with first. Thanks in advance for your patience!
โ11-18-2021 12:36 AM
I am sure there is a trick but I doubt it is the best way:
the actual notebooks store each cell as # COMMAND ------ and markdown as # MAGIC %md.
So you could fetch the actual notebook code and start rebuilding it in python with a loop/count over COMMAND or MAGIC.
But as I said: seems overkill. Databricks can parse it nicely so there has to be a way.
โ11-18-2021 01:06 AM
Maybe you can use displayHTML instead of markdown? Like that you actually have it as code:
displayHTML("insert text here").
It is not as clean as markdown though.
โ11-18-2021 03:35 AM
@Werner Stinckensโ I will experiment on that in few weeks using your ideas. I need it only when exception occur in notebook so maybe it will not be so big overkill. I will back to you.
โ11-18-2021 05:11 AM
you could also use the log analytics of your cloud provider.
For Azure f.e. we send all databricks logs to Log Analytics. I suppose on AWS/GCP there is also a similar thing.
(https://docs.microsoft.com/en-us/azure/databricks/administration-guide/account-settings/azure-diagnostic-logs)
Or send logs to some location which you can then parse with python
(https://docs.microsoft.com/en-us/azure/databricks/clusters/configure#cluster-log-delivery)
โ11-18-2021 08:24 AM
Hi @Hubert Dudekโ ,
The following command will print the path where your notebook is located. If you split the returned string and only select the last string, then you will be able to get the notebook name
notebook_name = dbutils.notebook.entry_point.getDbutils().notebook().getContext().notebookPath().get()
โ11-18-2021 08:40 AM
wow will test it tomorrow ๐ haven't known about dbutils.notebook.entry_point
โ11-23-2021 04:01 PM
Did this helped you? if it did, could you mark it as best response?
โ11-24-2021 03:13 AM
haven't tested yet (you now tomorrow in dev world can be quite long time) but I've selected your answer as the best
โ11-24-2021 05:19 AM
@Hubert Dudekโ - If I haven't told you, you are awesome!
โ11-24-2021 05:20 AM
Thank you. You too ๐
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโt want to miss the chance to attend and share knowledge.
If there isnโt a group near you, start one and help create a community that brings people together.
Request a New Group