<?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 Re: Invalid Path when getting Notebook Path in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/invalid-path-when-getting-notebook-path/m-p/101760#M40816</link>
    <description>&lt;P&gt;I actually think the major issue is that the above is undocumented and not supported. A supported and documented way of doing this would be much appreciated.&lt;/P&gt;</description>
    <pubDate>Wed, 11 Dec 2024 13:02:26 GMT</pubDate>
    <dc:creator>Steve_Harrison</dc:creator>
    <dc:date>2024-12-11T13:02:26Z</dc:date>
    <item>
      <title>Invalid Path when getting Notebook Path</title>
      <link>https://community.databricks.com/t5/data-engineering/invalid-path-when-getting-notebook-path/m-p/86831#M37343</link>
      <description>&lt;P&gt;The undocumented feature to get a notebook path as is great but it does not actually return a valid path that can be used in python, e.g.:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;from&lt;/SPAN&gt;&lt;SPAN&gt; pathlib &lt;/SPAN&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; Path&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;Path&lt;/SPAN&gt;&lt;SPAN&gt;(dbutils.notebook.entry_point.&lt;/SPAN&gt;&lt;SPAN&gt;getDbutils&lt;/SPAN&gt;&lt;SPAN&gt;().&lt;/SPAN&gt;&lt;SPAN&gt;notebook&lt;/SPAN&gt;&lt;SPAN&gt;().&lt;/SPAN&gt;&lt;SPAN&gt;getContext&lt;/SPAN&gt;&lt;SPAN&gt;().&lt;/SPAN&gt;&lt;SPAN&gt;notebookPath&lt;/SPAN&gt;&lt;SPAN&gt;().&lt;/SPAN&gt;&lt;SPAN&gt;get&lt;/SPAN&gt;&lt;SPAN&gt;()).&lt;/SPAN&gt;&lt;SPAN&gt;exists&lt;/SPAN&gt;&lt;SPAN&gt;())&lt;BR /&gt;&lt;BR /&gt;Always returns False. Is there a method of getting the actual path of a notebook?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The above suffers from two problems:&lt;/SPAN&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN&gt;It appears to strip off the /Workspace from the start of the path&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;It removes the suffix from the path&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN&gt;2 is not so much of an issue but the first one is a royal pain.&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 30 Aug 2024 10:17:22 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/invalid-path-when-getting-notebook-path/m-p/86831#M37343</guid>
      <dc:creator>Steve_Harrison</dc:creator>
      <dc:date>2024-08-30T10:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid Path when getting Notebook Path</title>
      <link>https://community.databricks.com/t5/data-engineering/invalid-path-when-getting-notebook-path/m-p/101750#M40808</link>
      <description>&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;SPAN&gt;The issue you're encountering with &lt;CODE&gt;dbutils.notebook.entry_point.getDbutils().notebook().getContext().notebookPath().get()&lt;/CODE&gt; not returning a valid path that can be used in Python is known. This method indeed strips off the &lt;CODE&gt;/Workspace&lt;/CODE&gt; from the start of the path and removes the suffix, which causes the &lt;CODE&gt;Path.exists()&lt;/CODE&gt; check to fail.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;SPAN&gt;To get the actual path of a notebook, you can prepend &lt;CODE&gt;/Workspace&lt;/CODE&gt; to the path returned by &lt;CODE&gt;getDbutils().notebook().getContext().notebookPath().get()&lt;/CODE&gt;. Here is an example of how you can modify your code to achieve this:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;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())&lt;/LI-CODE&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 11:49:51 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/invalid-path-when-getting-notebook-path/m-p/101750#M40808</guid>
      <dc:creator>Walter_C</dc:creator>
      <dc:date>2024-12-11T11:49:51Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid Path when getting Notebook Path</title>
      <link>https://community.databricks.com/t5/data-engineering/invalid-path-when-getting-notebook-path/m-p/101760#M40816</link>
      <description>&lt;P&gt;I actually think the major issue is that the above is undocumented and not supported. A supported and documented way of doing this would be much appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 13:02:26 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/invalid-path-when-getting-notebook-path/m-p/101760#M40816</guid>
      <dc:creator>Steve_Harrison</dc:creator>
      <dc:date>2024-12-11T13:02:26Z</dc:date>
    </item>
  </channel>
</rss>

