<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How can I programmatically get my notebook path? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-can-i-programmatically-get-my-notebook-path/m-p/25334#M17607</link>
    <description>&lt;P&gt;I'm writing some code that trains a ML model using MLflow and a given set of hyperparameters. This code is going to be run by several folks on my team and I want to make sure that the experiment that get's created is created in the same directory as the notebook - i.e. if someone clones the notebook into their own user folder, the MLflow experiment should be pointed to their notebooks new location. &lt;/P&gt;</description>
    <pubDate>Thu, 10 Jun 2021 12:19:55 GMT</pubDate>
    <dc:creator>User16752241457</dc:creator>
    <dc:date>2021-06-10T12:19:55Z</dc:date>
    <item>
      <title>How can I programmatically get my notebook path?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-can-i-programmatically-get-my-notebook-path/m-p/25334#M17607</link>
      <description>&lt;P&gt;I'm writing some code that trains a ML model using MLflow and a given set of hyperparameters. This code is going to be run by several folks on my team and I want to make sure that the experiment that get's created is created in the same directory as the notebook - i.e. if someone clones the notebook into their own user folder, the MLflow experiment should be pointed to their notebooks new location. &lt;/P&gt;</description>
      <pubDate>Thu, 10 Jun 2021 12:19:55 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-can-i-programmatically-get-my-notebook-path/m-p/25334#M17607</guid>
      <dc:creator>User16752241457</dc:creator>
      <dc:date>2021-06-10T12:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: How can I programmatically get my notebook path?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-can-i-programmatically-get-my-notebook-path/m-p/25335#M17608</link>
      <description>&lt;P&gt;In Scala you can use the "dbutils.notebook.getContext.notebookPath" function. If needed for Python or R, the only way to share this value would be to use widgets. Run the code with %scala, pass the value into a widget, then read the widget in Python or R. &lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 19:38:48 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-can-i-programmatically-get-my-notebook-path/m-p/25335#M17608</guid>
      <dc:creator>Ryan_Chynoweth</dc:creator>
      <dc:date>2021-06-21T19:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: How can I programmatically get my notebook path?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-can-i-programmatically-get-my-notebook-path/m-p/25336#M17609</link>
      <description>&lt;P&gt;In Scala the call is &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;dbutils.notebook.getContext.notebookPath.get&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In Python the call is&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;dbutils.entry_point.getDbutils().notebook().getContext().notebookPath().getOrElse(None)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If you need it in another language, a common practice would be to pass it through spark config.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ignoring that we can get the value in Python (as seen above), if you start with a Scala cell like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%scala
val path = dbutils.notebook.getContext.notebookPath.get
spark.conf.set("com.whaterver.notebook-path")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And then in the next Python cell (the same concepts applies to R and SQL)&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%python
path = spark.conf.get("com.whaterver.notebook-path")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You just want to adjust the configuration parameter's name to be a unique value so as not to accidentally clash with something. For example, we often use "com.databricks.training"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 19:51:33 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-can-i-programmatically-get-my-notebook-path/m-p/25336#M17609</guid>
      <dc:creator>User16857281974</dc:creator>
      <dc:date>2021-07-30T19:51:33Z</dc:date>
    </item>
  </channel>
</rss>

