<?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: Relative Paths in Python? in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/relative-paths-in-python/m-p/660496#M21992</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think I found something that works pretty easily from &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.faqs.org/docs/diveintopython/regression_path.html"&gt;http://www.faqs.org/docs/diveintopython/regression_path.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;import sys, os&lt;BR /&gt;&lt;BR /&gt;print 'sys.argv[0] =', sys.argv[0]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;pathname = os.path.dirname(sys.argv[0])&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;print 'path =', pathname&lt;BR /&gt;print 'full path =', os.path.abspath(pathname)&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I modified it in my script to just include;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;pathname = os.path.dirname(sys.argv[0])&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And then when I defined my local variables I went with;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;VariableName = pathname + "/Folder/File"&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Jordan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 05 May 2010 14:33:12 GMT</pubDate>
    <dc:creator>JordanHoaglund</dc:creator>
    <dc:date>2010-05-05T14:33:12Z</dc:date>
    <item>
      <title>Relative Paths in Python?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/relative-paths-in-python/m-p/660494#M21990</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is probably a pretty basic question, but how do you set relative paths in Python?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The script sits in a folder called SDE.&amp;nbsp; It is run from a toolbox also located in the SDE folder.&amp;nbsp; It needs to recognize data within folders that are also located in the SDE folder (horizontal to the script in the directory tree).&amp;nbsp; Any Suggestions?&amp;nbsp; I've tried just about every combination of ../ and ./ in front of filepaths in the script to no avail.&amp;nbsp; Maybe it's not that easy??&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Jordan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 May 2010 21:30:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/relative-paths-in-python/m-p/660494#M21990</guid>
      <dc:creator>JordanHoaglund</dc:creator>
      <dc:date>2010-05-04T21:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: Relative Paths in Python?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/relative-paths-in-python/m-p/660495#M21991</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Unfortunately, this is quite difficult to accomplish in 9.3.1, but in 10.0 you can use the __file__ global in script tools to determine the folder a script is running in. The same __file__ global can be used in script tools in 9.3.1, but only if the script is marked to run out of process (in the properties dialog).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The recipe you'd use is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;os.path.join(os.path.dirname(__file__), "my_sde.sde")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 May 2010 04:17:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/relative-paths-in-python/m-p/660495#M21991</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2010-05-05T04:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: Relative Paths in Python?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/relative-paths-in-python/m-p/660496#M21992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think I found something that works pretty easily from &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.faqs.org/docs/diveintopython/regression_path.html"&gt;http://www.faqs.org/docs/diveintopython/regression_path.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;import sys, os&lt;BR /&gt;&lt;BR /&gt;print 'sys.argv[0] =', sys.argv[0]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;pathname = os.path.dirname(sys.argv[0])&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;print 'path =', pathname&lt;BR /&gt;print 'full path =', os.path.abspath(pathname)&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I modified it in my script to just include;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;pathname = os.path.dirname(sys.argv[0])&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And then when I defined my local variables I went with;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;VariableName = pathname + "/Folder/File"&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Jordan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 May 2010 14:33:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/relative-paths-in-python/m-p/660496#M21992</guid>
      <dc:creator>JordanHoaglund</dc:creator>
      <dc:date>2010-05-05T14:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: Relative Paths in Python?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/relative-paths-in-python/m-p/660497#M21993</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;See the ArcGIS help topic&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Techniques_for_sharing_Python_scripts"&gt;Techniques for sharing Python scripts&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The first section "Finding data relative to the script location" shows you how to do this...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 May 2010 17:24:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/relative-paths-in-python/m-p/660497#M21993</guid>
      <dc:creator>DaleHoneycutt</dc:creator>
      <dc:date>2010-05-13T17:24:17Z</dc:date>
    </item>
  </channel>
</rss>

