<?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>idea Make Python Toolbox parameters a namedtuple instead of a list in ArcGIS Pro Ideas</title>
    <link>https://community.esri.com/t5/arcgis-pro-ideas/make-python-toolbox-parameters-a-namedtuple/idi-p/1133743</link>
    <description>&lt;P&gt;ArcGIS Pro passes parameters to&amp;nbsp;Python Toolbox (.pyt) Tool&amp;nbsp;updateParameters, updateMessages and&amp;nbsp;&lt;SPAN&gt;execute methods as a list.&amp;nbsp; Changing this to a namedtuple by default would allow access by parameter name as well as by index.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Currently users can create a dictionary or a namedtuple themselves, e.g the way I do it is below, but I've also seen some fairly awkward attempts with globals and loops.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;As a dict:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;class Tool
    etc...
    
    def execute(self, parameters, messages):
        parameters = {p.name: p for p in parameters}
        # do something with parameters["some_name"]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As a namedtuple:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from collections import namedtuple

class Tool
    etc...

    def execute(self, parameters, messages):
        parameters = namedtuple('Parameters', (p.name for p in parameters))(*parameters)
        # do something with parameters[0] or parameters.some_name&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jan 2022 08:34:48 GMT</pubDate>
    <dc:creator>Luke_Pinner</dc:creator>
    <dc:date>2022-01-14T08:34:48Z</dc:date>
    <item>
      <title>Make Python Toolbox parameters a namedtuple instead of a list</title>
      <link>https://community.esri.com/t5/arcgis-pro-ideas/make-python-toolbox-parameters-a-namedtuple/idi-p/1133743</link>
      <description>&lt;P&gt;ArcGIS Pro passes parameters to&amp;nbsp;Python Toolbox (.pyt) Tool&amp;nbsp;updateParameters, updateMessages and&amp;nbsp;&lt;SPAN&gt;execute methods as a list.&amp;nbsp; Changing this to a namedtuple by default would allow access by parameter name as well as by index.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Currently users can create a dictionary or a namedtuple themselves, e.g the way I do it is below, but I've also seen some fairly awkward attempts with globals and loops.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;As a dict:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;class Tool
    etc...
    
    def execute(self, parameters, messages):
        parameters = {p.name: p for p in parameters}
        # do something with parameters["some_name"]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As a namedtuple:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from collections import namedtuple

class Tool
    etc...

    def execute(self, parameters, messages):
        parameters = namedtuple('Parameters', (p.name for p in parameters))(*parameters)
        # do something with parameters[0] or parameters.some_name&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 08:34:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-ideas/make-python-toolbox-parameters-a-namedtuple/idi-p/1133743</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2022-01-14T08:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: Make Python Toolbox parameters a namedtuple instead of a list</title>
      <link>https://community.esri.com/t5/arcgis-pro-ideas/make-python-toolbox-parameters-a-namedtuple/idc-p/1133752#M18314</link>
      <description>&lt;P&gt;This would be great.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;parameters[1]&lt;/STRONG&gt; is just so non-descriptive as opposed to &lt;STRONG&gt;parameters.InTable&lt;/STRONG&gt; or &lt;STRONG&gt;parameters["InTable"]&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;using indices is just suicide when you are still adding/removing/moving parameters&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I use the dictionary approach in every one of my tools and it's not too much hassle, but it could be completely avoided if parameters was a named tuple from the start. That would also save me from having to create the dict multiple times in a tool (&lt;STRONG&gt;updateParameters()&lt;/STRONG&gt;, &lt;STRONG&gt;updateMessages()&lt;/STRONG&gt; and &lt;STRONG&gt;execute()&lt;/STRONG&gt;)&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 06:41:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-ideas/make-python-toolbox-parameters-a-namedtuple/idc-p/1133752#M18314</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-01-14T06:41:16Z</dc:date>
    </item>
    <item>
      <title>Re: Make Python Toolbox parameters a namedtuple instead of a list</title>
      <link>https://community.esri.com/t5/arcgis-pro-ideas/make-python-toolbox-parameters-a-namedtuple/idc-p/1133905#M18318</link>
      <description>&lt;P&gt;This would be super useful.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 16:09:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-ideas/make-python-toolbox-parameters-a-namedtuple/idc-p/1133905#M18318</guid>
      <dc:creator>AJR</dc:creator>
      <dc:date>2022-01-14T16:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: Make Python Toolbox parameters a namedtuple instead of a list - Status changed to: Implemented</title>
      <link>https://community.esri.com/t5/arcgis-pro-ideas/make-python-toolbox-parameters-a-namedtuple/idc-p/1355157#M27318</link>
      <description>&lt;P&gt;The following functions and classes now support name-based parameter referencing:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/3.2/arcpy/functions/copyparameter.htm" target="_blank" rel="noopener"&gt;CopyParameter&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/result.htm" target="_blank" rel="noopener"&gt;Result&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/getparameter.htm" target="_blank" rel="noopener"&gt;GetParameter&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/3.2/arcpy/functions/getparameterastext.htm" target="_blank" rel="noopener"&gt;GetParameterAsText&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/3.2/arcpy/functions/getparametervalue.htm" target="_blank" rel="noopener"&gt;GetParameterValue&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/setparameter.htm" target="_blank" rel="noopener"&gt;SetParameter&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/3.2/arcpy/functions/setparameterastext.htm" target="_blank" rel="noopener"&gt;SetParameterAsText&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Please see the&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/get-started/whats-new-in-arcgis-pro.htm" target="_blank" rel="noopener"&gt;What's New documentation&lt;/A&gt;&amp;nbsp;for more new features in Pro 3.2. Additionally, we have also posted a&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-ideas-blog/your-ideas-in-arcgis-pro-3-2/ba-p/1346155" target="_blank" rel="noopener"&gt;Your Ideas in ArcGIS Pro 3.2 blog and video&lt;/A&gt;, take a look if interested!&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2023 15:36:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-ideas/make-python-toolbox-parameters-a-namedtuple/idc-p/1355157#M27318</guid>
      <dc:creator>HannesZiegler</dc:creator>
      <dc:date>2023-11-30T15:36:15Z</dc:date>
    </item>
  </channel>
</rss>

