<?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 to print the path of a .py file or a notebook? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-print-the-path-of-a-py-file-or-a-notebook/m-p/16620#M10784</link>
    <description>&lt;P&gt;I have stored a &lt;A href="https://test.py" alt="https://test.py" target="_blank"&gt;test.py&lt;/A&gt; in the dbfs at the below location "&lt;B&gt;/dbfs/FileStore/shared_uploads/krishna@company.com/Project_Folder/&lt;/B&gt;&lt;A href="https://test.py" alt="https://test.py" target="_blank"&gt;&lt;B&gt;test.py&lt;/B&gt;&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a print statement in &lt;A href="https://test.py" alt="https://test.py" target="_blank"&gt;test.py&lt;/A&gt; which says the below&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;print( os.getcwd() )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and it prints the below&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;'/databricks/driver'&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is utterly weird as I am not getting the correct path&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Btw, the same thing happens with a notebook as well. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I have a notebook "test_nb.ipynb"" at the below location&lt;/P&gt;&lt;P&gt;"&lt;B&gt;/dbfs/FileStore/shared_uploads/krishna@company.com/Project_Folder/test_nb.ipynb"&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have the same print statement in test_nb.py which says the below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;print( os.getcwd() )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and it prints the below&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;'/databricks/driver'&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Can someone please help me to print the correct path ?? When you answer, please can you make sure not to make the answer specific to a notebook as I actually need to print the path of a .py file&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TIA&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Dec 2022 22:56:57 GMT</pubDate>
    <dc:creator>KrishZ</dc:creator>
    <dc:date>2022-12-15T22:56:57Z</dc:date>
    <item>
      <title>How to print the path of a .py file or a notebook?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-print-the-path-of-a-py-file-or-a-notebook/m-p/16620#M10784</link>
      <description>&lt;P&gt;I have stored a &lt;A href="https://test.py" alt="https://test.py" target="_blank"&gt;test.py&lt;/A&gt; in the dbfs at the below location "&lt;B&gt;/dbfs/FileStore/shared_uploads/krishna@company.com/Project_Folder/&lt;/B&gt;&lt;A href="https://test.py" alt="https://test.py" target="_blank"&gt;&lt;B&gt;test.py&lt;/B&gt;&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a print statement in &lt;A href="https://test.py" alt="https://test.py" target="_blank"&gt;test.py&lt;/A&gt; which says the below&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;print( os.getcwd() )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and it prints the below&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;'/databricks/driver'&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is utterly weird as I am not getting the correct path&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Btw, the same thing happens with a notebook as well. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I have a notebook "test_nb.ipynb"" at the below location&lt;/P&gt;&lt;P&gt;"&lt;B&gt;/dbfs/FileStore/shared_uploads/krishna@company.com/Project_Folder/test_nb.ipynb"&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have the same print statement in test_nb.py which says the below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;print( os.getcwd() )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and it prints the below&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;'/databricks/driver'&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Can someone please help me to print the correct path ?? When you answer, please can you make sure not to make the answer specific to a notebook as I actually need to print the path of a .py file&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TIA&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 22:56:57 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-print-the-path-of-a-py-file-or-a-notebook/m-p/16620#M10784</guid>
      <dc:creator>KrishZ</dc:creator>
      <dc:date>2022-12-15T22:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to print the path of a .py file or a notebook?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-print-the-path-of-a-py-file-or-a-notebook/m-p/16621#M10785</link>
      <description>&lt;P&gt;You can get the notebook path using following code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;dbutils.notebook.\
entry_point.getDbutils().\
notebook().\
getContext().\
notebookPath().\
value()&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Or, you can use Workspace APIs to list notebooks.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2022 02:11:00 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-print-the-path-of-a-py-file-or-a-notebook/m-p/16621#M10785</guid>
      <dc:creator>AmanSehgal</dc:creator>
      <dc:date>2022-12-16T02:11:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to print the path of a .py file or a notebook?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-print-the-path-of-a-py-file-or-a-notebook/m-p/16622#M10786</link>
      <description>&lt;P&gt;No bro.. this is just specifically for notebooks... Do you know something for .py files?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Moreover the code above doesn't even work for notebooks .. The answer I got with your code is below &lt;/P&gt;&lt;P&gt;&lt;B&gt;/Users/krishna@company.com/Project_Folder/test_nb.ipynb&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;while I expected the path to be where I created the notebook.. (below)&lt;/P&gt;&lt;P&gt;"&lt;B&gt;/dbfs/FileStore/shared_uploads/krishna@company.com/Project_Folder/test_nb.ipynb"&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2022 05:39:38 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-print-the-path-of-a-py-file-or-a-notebook/m-p/16622#M10786</guid>
      <dc:creator>KrishZ</dc:creator>
      <dc:date>2022-12-16T05:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to print the path of a .py file or a notebook?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-print-the-path-of-a-py-file-or-a-notebook/m-p/16623#M10787</link>
      <description>&lt;P&gt;You can use a recursive function to list everything within a directory path, and then add a filter for .py files.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;def get_dir_content(ls_path):
    for dir_path in dbutils.fs.ls(ls_path):
        if dir_path.isFile():
            yield dir_path.path
        elif dir_path.isDir() and ls_path != dir_path.path:
            yield from get_dir_content(dir_path.path)
    
list(get_dir_content('dbfs:/FileStore'))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Source: &lt;A href="https://stackoverflow.com/questions/63955823/list-the-files-of-a-directory-and-subdirectory-recursively-in-databricksdbfs" alt="https://stackoverflow.com/questions/63955823/list-the-files-of-a-directory-and-subdirectory-recursively-in-databricksdbfs" target="_blank"&gt;stackvoerflow&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2022 06:44:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-print-the-path-of-a-py-file-or-a-notebook/m-p/16623#M10787</guid>
      <dc:creator>AmanSehgal</dc:creator>
      <dc:date>2022-12-16T06:44:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to print the path of a .py file or a notebook?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-print-the-path-of-a-py-file-or-a-notebook/m-p/16624#M10788</link>
      <description>&lt;P&gt;Hey @Krishna Zanwar​&amp;nbsp; Please use the below code this will work&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/994i44A06F55952C5DDA/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and as you want the specific location you can create a custom code and format the path using a python formatter , it will give you desired result .&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2022 15:44:50 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-print-the-path-of-a-py-file-or-a-notebook/m-p/16624#M10788</guid>
      <dc:creator>Aviral-Bhardwaj</dc:creator>
      <dc:date>2022-12-16T15:44:50Z</dc:date>
    </item>
  </channel>
</rss>

