<?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: Unzip with python - Using ToolValidator in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/unzip-with-python-using-toolvalidator/m-p/714606#M55444</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;str(self.params[0].value)&lt;/SPAN&gt;&lt;SPAN&gt; or &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;self.params[0].value.value&lt;/SPAN&gt;&lt;SPAN&gt; in the validator.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 24 Sep 2012 18:52:13 GMT</pubDate>
    <dc:creator>JasonScheirer</dc:creator>
    <dc:date>2012-09-24T18:52:13Z</dc:date>
    <item>
      <title>Unzip with python - Using ToolValidator</title>
      <link>https://community.esri.com/t5/python-questions/unzip-with-python-using-toolvalidator/m-p/714600#M55438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to unzip a file to a directory, and show all the files from the zipped-file in the tool-parameters on self.params[2]. I think this should work with the ToolValidator. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So I write in the Validator the following script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; def updateParameters(self): &amp;nbsp;&amp;nbsp;&amp;nbsp; """Modify the values and properties of parameters before internal &amp;nbsp;&amp;nbsp;&amp;nbsp; validation is performed.&amp;nbsp; This method is called whenever a parmater &amp;nbsp;&amp;nbsp;&amp;nbsp; has been changed.""" &amp;nbsp;&amp;nbsp;&amp;nbsp; if self.params[0].value: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list = [] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zip = zipfile.ZipFile(self.params[0].value, "r") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for zfile in zip.namelist(): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list.append(zfile.name) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[2].filter.list = list&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My problem now is that I get the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;ERROR &lt;BR /&gt;updateParameters Execution Error: Runtime error : global name 'zipfile' is not defined&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have already imported zipfile in def __init__(self)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can someone help me?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks a lot for your help!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Karsten&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Sep 2012 18:04:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unzip-with-python-using-toolvalidator/m-p/714600#M55438</guid>
      <dc:creator>KarstenRank</dc:creator>
      <dc:date>2012-09-24T18:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Unzip with python - Using ToolValidator</title>
      <link>https://community.esri.com/t5/python-questions/unzip-with-python-using-toolvalidator/m-p/714601#M55439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You will need to pass it as a parameter to the function or make it a global variable.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Sep 2012 18:15:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unzip-with-python-using-toolvalidator/m-p/714601#M55439</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-09-24T18:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: Unzip with python - Using ToolValidator</title>
      <link>https://community.esri.com/t5/python-questions/unzip-with-python-using-toolvalidator/m-p/714602#M55440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Did you import zipfile?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Sep 2012 18:17:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unzip-with-python-using-toolvalidator/m-p/714602#M55440</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2012-09-24T18:17:16Z</dc:date>
    </item>
    <item>
      <title>Re: Unzip with python - Using ToolValidator</title>
      <link>https://community.esri.com/t5/python-questions/unzip-with-python-using-toolvalidator/m-p/714603#M55441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have import zipfile in the ToolValidator and in the python script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;class ToolValidator:
&amp;nbsp; """Class for validating a tool's parameter values and controlling
&amp;nbsp; the behavior of the tool's dialog."""

&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Setup arcpy and the list of tool parameters."""
&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy
&amp;nbsp;&amp;nbsp;&amp;nbsp; import zipfile
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; self.params = arcpy.GetParameterInfo()

&amp;nbsp; def initializeParameters(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Refine the properties of a tool's parameters.&amp;nbsp; This method is
&amp;nbsp;&amp;nbsp;&amp;nbsp; called when the tool is opened."""
&amp;nbsp;&amp;nbsp;&amp;nbsp; return

&amp;nbsp; def updateParameters(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Modify the values and properties of parameters before internal
&amp;nbsp;&amp;nbsp;&amp;nbsp; validation is performed.&amp;nbsp; This method is called whenever a parmater
&amp;nbsp;&amp;nbsp;&amp;nbsp; has been changed."""
&amp;nbsp;&amp;nbsp;&amp;nbsp; if self.params[0].value:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list = []
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zip = zipfile.ZipFile(self.params[0].value, "r")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for zfile in zip.namelist():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list.append(zfile.name)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[2].filter.list = list

&amp;nbsp; def updateMessages(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Modify the messages created by internal validation for each tool
&amp;nbsp;&amp;nbsp;&amp;nbsp; parameter.&amp;nbsp; This method is called after internal validation."""
&amp;nbsp;&amp;nbsp;&amp;nbsp; return
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But how can I pass it as a parameter to the function or make it a global variable?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:35:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unzip-with-python-using-toolvalidator/m-p/714603#M55441</guid>
      <dc:creator>KarstenRank</dc:creator>
      <dc:date>2021-12-12T06:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: Unzip with python - Using ToolValidator</title>
      <link>https://community.esri.com/t5/python-questions/unzip-with-python-using-toolvalidator/m-p/714604#M55442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Why not just put the import at the top of updateParameters? Python's smart about how it imports modules and if it's already imported it once it'll stay in memory and won't take any time at all if it hits another import line later for the same thing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What version of ArcGIS are you using?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Sep 2012 18:32:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unzip-with-python-using-toolvalidator/m-p/714604#M55442</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2012-09-24T18:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: Unzip with python - Using ToolValidator</title>
      <link>https://community.esri.com/t5/python-questions/unzip-with-python-using-toolvalidator/m-p/714605#M55443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm using ArcMap 10.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now I get another error. The import at the beginning has helped loading the module.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;ERROR &lt;BR /&gt;updateParameters Execution Error: Runtime error : ValueObject: Get attribute seek does not exist&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Sep 2012 18:45:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unzip-with-python-using-toolvalidator/m-p/714605#M55443</guid>
      <dc:creator>KarstenRank</dc:creator>
      <dc:date>2012-09-24T18:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Unzip with python - Using ToolValidator</title>
      <link>https://community.esri.com/t5/python-questions/unzip-with-python-using-toolvalidator/m-p/714606#M55444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;str(self.params[0].value)&lt;/SPAN&gt;&lt;SPAN&gt; or &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;self.params[0].value.value&lt;/SPAN&gt;&lt;SPAN&gt; in the validator.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Sep 2012 18:52:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unzip-with-python-using-toolvalidator/m-p/714606#M55444</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2012-09-24T18:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: Unzip with python - Using ToolValidator</title>
      <link>https://community.esri.com/t5/python-questions/unzip-with-python-using-toolvalidator/m-p/714607#M55445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks a lot!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It works now!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Greetings from Bavaria!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Karsten&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Sep 2012 19:04:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unzip-with-python-using-toolvalidator/m-p/714607#M55445</guid>
      <dc:creator>KarstenRank</dc:creator>
      <dc:date>2012-09-24T19:04:53Z</dc:date>
    </item>
  </channel>
</rss>

