<?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: Writing a script to self indexing list of fields in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/writing-a-script-to-self-indexing-list-of-fields/m-p/1076401#M61612</link>
    <description>&lt;P&gt;Thanks BlakeTerhune for the help. I haven't seen this method before nor did I even know about it. I will definitely have to give this a try when I get around to it. This would be extremely helpful for making general script tools rather than having to script something specific all the time.&lt;/P&gt;</description>
    <pubDate>Wed, 07 Jul 2021 17:47:01 GMT</pubDate>
    <dc:creator>RPGIS</dc:creator>
    <dc:date>2021-07-07T17:47:01Z</dc:date>
    <item>
      <title>Writing a script to self indexing list of fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-a-script-to-self-indexing-list-of-fields/m-p/1075219#M61541</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I was wondering if there is a way to write a script where a list of fields can be self indexing for the search or update cursor?&lt;/P&gt;&lt;P&gt;The reason for this is because I am trying to set up a script tool in such a manner that regardless of the order of the fields, the script will be intelligent enough to identify those fields and then be able search through the attributes with those fields without the need for manually indexing. I have a list of important attributes as well as the fields in which those values reside, but I would write the script to self index and search for those specific values.&lt;/P&gt;&lt;P&gt;I figured enumerating the list of fields and creating a dictionary for the enumerated values is a start, but figuring out how to go from there is a bit tricky for me at the moment. So I wanted to reach out and see if anyone has ever attempted this, and if so, how did you write it.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jul 2021 16:25:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-a-script-to-self-indexing-list-of-fields/m-p/1075219#M61541</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2021-07-02T16:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting self indexing list of fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-a-script-to-self-indexing-list-of-fields/m-p/1075241#M61543</link>
      <description>It’s possible-&lt;BR /&gt;&lt;BR /&gt;You can use yourfieldlist.index(fieldname) on your list of fields and it will give you the index to use. However, the list of fields needs to match the list of fields you are using in the method.&lt;BR /&gt;&lt;BR /&gt;I can share an example here shortly on how to implement it if someone else doesn’t beat me to it.&lt;BR /&gt;</description>
      <pubDate>Fri, 02 Jul 2021 17:28:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-a-script-to-self-indexing-list-of-fields/m-p/1075241#M61543</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-07-02T17:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a script to self indexing list of fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-a-script-to-self-indexing-list-of-fields/m-p/1075248#M61544</link>
      <description>&lt;P&gt;Here is a little code that is creating the field list, then using the list to get the index for the cursor.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;updatedflds = [f.name for f in arcpy.ListFields(updatedAddress)]    

with arcpy.da.UpdateCursor(adr, updatedflds, sql) as uCur:
    for row in uCur:
        # set the row values
        for fld in updatedflds:
            row[updatedflds.index(fld)] = fldvalue&lt;/LI-CODE&gt;&lt;P&gt;I have an example for using a dictionary if you want to see that one as well.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jul 2021 17:38:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-a-script-to-self-indexing-list-of-fields/m-p/1075248#M61544</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-07-02T17:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a script to self indexing list of fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-a-script-to-self-indexing-list-of-fields/m-p/1075351#M61550</link>
      <description>&lt;P&gt;What about this spiffy trick where you can reference the values of a row by field name using a dictionary?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def rows_as_dicts(cursor):
    colnames = cursor.fields
    for row in cursor:
        yield dict(zip(colnames, row))

with arcpy.da.SearchCursor(r'c:\data\world.gdb\world_cities', '*') as sc:
    for row in rows_as_dicts(sc):
        print row['CITY_NAME']&lt;/LI-CODE&gt;&lt;P&gt;&lt;A href="https://arcpy.wordpress.com/2012/07/12/getting-arcpy-da-rows-back-as-dictionaries/" target="_blank"&gt;Getting arcpy.da rows back as dictionaries | ArcPy Café (wordpress.com)&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jul 2021 20:41:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-a-script-to-self-indexing-list-of-fields/m-p/1075351#M61550</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-07-02T20:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a script to self indexing list of fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-a-script-to-self-indexing-list-of-fields/m-p/1076230#M61602</link>
      <description>&lt;P&gt;Thanks Jeff for sending me this sample code. This is a lot closer to what I was looking for. I completely forgot that I could have used the ().index method to auto-identify the rows without the needing to specify the index manually.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jul 2021 11:43:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-a-script-to-self-indexing-list-of-fields/m-p/1076230#M61602</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2021-07-07T11:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a script to self indexing list of fields</title>
      <link>https://community.esri.com/t5/python-questions/writing-a-script-to-self-indexing-list-of-fields/m-p/1076401#M61612</link>
      <description>&lt;P&gt;Thanks BlakeTerhune for the help. I haven't seen this method before nor did I even know about it. I will definitely have to give this a try when I get around to it. This would be extremely helpful for making general script tools rather than having to script something specific all the time.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jul 2021 17:47:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-a-script-to-self-indexing-list-of-fields/m-p/1076401#M61612</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2021-07-07T17:47:01Z</dc:date>
    </item>
  </channel>
</rss>

