<?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: python script tool - use folder or file location under validation in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-script-tool-use-folder-or-file-location/m-p/674418#M52164</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If your Json file is placed under the same folder your python toolbox/script you can use "__File__" Attribute to get the current directory. Please try following code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data= os.path.join(os.path.dirname(__file__),r'data.json')&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 24 Mar 2018 08:44:47 GMT</pubDate>
    <dc:creator>Madanbhurati</dc:creator>
    <dc:date>2018-03-24T08:44:47Z</dc:date>
    <item>
      <title>python script tool - use folder or file location under validation</title>
      <link>https://community.esri.com/t5/python-questions/python-script-tool-use-folder-or-file-location/m-p/674417#M52163</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i have tool one of the parameter have is folder location (can be file it self) of jason file with parameters organized&amp;nbsp;in dictionary&amp;nbsp;&lt;BR /&gt;i need to use this location under the" def updateParameters(self): " so i can open the&amp;nbsp; jason and load the parameters to the drop down menu&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is the part that i cant figure if i used the real path with the dn like&amp;nbsp; dn = "c:/workspace"&lt;BR /&gt;it works great&amp;nbsp; but i need the path the user enter when the tool is used&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data= os.path.join(dn, 'data.json')&lt;BR /&gt; with open(&lt;SPAN&gt;data&lt;/SPAN&gt;) as data_file:&lt;BR /&gt; dic = &lt;SPAN&gt;data&lt;/SPAN&gt;.load(data_file)&lt;BR /&gt; self.params[3].filter.list = dic.keys()&lt;BR /&gt; return&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Mar 2018 19:53:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-tool-use-folder-or-file-location/m-p/674417#M52163</guid>
      <dc:creator>OrrGvili</dc:creator>
      <dc:date>2018-03-23T19:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: python script tool - use folder or file location under validation</title>
      <link>https://community.esri.com/t5/python-questions/python-script-tool-use-folder-or-file-location/m-p/674418#M52164</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If your Json file is placed under the same folder your python toolbox/script you can use "__File__" Attribute to get the current directory. Please try following code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data= os.path.join(os.path.dirname(__file__),r'data.json')&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 24 Mar 2018 08:44:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-tool-use-folder-or-file-location/m-p/674418#M52164</guid>
      <dc:creator>Madanbhurati</dc:creator>
      <dc:date>2018-03-24T08:44:47Z</dc:date>
    </item>
    <item>
      <title>Re: python script tool - use folder or file location under validation</title>
      <link>https://community.esri.com/t5/python-questions/python-script-tool-use-folder-or-file-location/m-p/674419#M52165</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;IMG __jive_id="399775" alt="" class="image-2 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/399775_Params.png" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry, I miss understood your question, please review following code written for&amp;nbsp;txt file, however you can change it for Json file. attached snapshot shows two parameters,&amp;nbsp;Folder and List of Strings. Once you select the folder containing text file,&amp;nbsp;using parameter "Add dialog box", your second parameter will be populated with text list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;def updateParameters(self):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; user_path=self.params[0].value&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data =os.path.join(str(user_path),r'Msb.txt')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; results = []&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; with open(data) as data_file:&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;for line in data_file:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;results.append(line)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[1].filter.list = results&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 24 Mar 2018 11:08:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-tool-use-folder-or-file-location/m-p/674419#M52165</guid>
      <dc:creator>Madanbhurati</dc:creator>
      <dc:date>2018-03-24T11:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: python script tool - use folder or file location under validation</title>
      <link>https://community.esri.com/t5/python-questions/python-script-tool-use-folder-or-file-location/m-p/674420#M52166</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks&amp;nbsp;&lt;BR /&gt;Last night found the solution&lt;BR /&gt;part of the problem was&amp;nbsp; &amp;nbsp;that&amp;nbsp;&lt;SPAN style="background-color: #ffffff;"&gt;self.params[0].value throw exception&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #222222; background-color: #ffffff; font-size: 12.8px;"&gt;when change it to&amp;nbsp; "with open(self.params[3].value.&lt;/SPAN&gt;&lt;SPAN style="color: #222222; background-color: #ffffff; font-size: 12.8px;"&gt;value) as data_file:"&amp;nbsp; solved the problem&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;.value vs .value.value&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 25 Mar 2018 07:22:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-tool-use-folder-or-file-location/m-p/674420#M52166</guid>
      <dc:creator>OrrGvili</dc:creator>
      <dc:date>2018-03-25T07:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: python script tool - use folder or file location under validation</title>
      <link>https://community.esri.com/t5/python-questions/python-script-tool-use-folder-or-file-location/m-p/674421#M52167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you could probablu use .valueAsText instead of value.value. Thwat way, you would get the file path as string to pass to open().&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Oct 2018 18:59:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-tool-use-folder-or-file-location/m-p/674421#M52167</guid>
      <dc:creator>philnagel</dc:creator>
      <dc:date>2018-10-11T18:59:18Z</dc:date>
    </item>
  </channel>
</rss>

