<?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: ArcPro 3.1.2 - How to search and update fields in arcpy.da.UpdateCursor using field names and not index? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpro-3-1-2-how-to-search-and-update-fields-in/m-p/1359794#M69393</link>
    <description>&lt;P&gt;I use &lt;A href="https://arcpy.wordpress.com/2012/07/12/getting-arcpy-da-rows-back-as-dictionaries/" target="_self"&gt;this little function&lt;/A&gt; to iterate the rows as a dictionary instead of a tuple.&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;</description>
    <pubDate>Tue, 12 Dec 2023 17:20:52 GMT</pubDate>
    <dc:creator>BlakeTerhune</dc:creator>
    <dc:date>2023-12-12T17:20:52Z</dc:date>
    <item>
      <title>ArcPro 3.1.2 - How to search and update fields in arcpy.da.UpdateCursor using field names and not index?</title>
      <link>https://community.esri.com/t5/python-questions/arcpro-3-1-2-how-to-search-and-update-fields-in/m-p/1359773#M69391</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;In a Python script, I use arcpy.da.UpdateCursor but I need to read/write into rows &lt;U&gt;using field names and not indexes&lt;/U&gt;, because fields to update are given as a parameter by the user.&lt;/P&gt;&lt;P&gt;When creating the update cursor, I select all fields '*' in order manipulate any fields.&lt;/P&gt;&lt;P&gt;However, it is a pain to read/update rows using indexes (dozens of fields)! I know rows are tuples but I really need to access fields using field names.&lt;/P&gt;&lt;P&gt;I spent time looking at documentation and posts but cannot find any proper syntax.&lt;/P&gt;&lt;P&gt;Help would be appreciated&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 16:54:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpro-3-1-2-how-to-search-and-update-fields-in/m-p/1359773#M69391</guid>
      <dc:creator>VincentLaunstorfer</dc:creator>
      <dc:date>2023-12-12T16:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPro 3.1.2 - How to search and update fields in arcpy.da.UpdateCursor using field names and not index?</title>
      <link>https://community.esri.com/t5/python-questions/arcpro-3-1-2-how-to-search-and-update-fields-in/m-p/1359788#M69392</link>
      <description>&lt;P&gt;The row is a tuple, so you can use index(). Something along the lines of:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.UpdateCursor(fc, "*") as cursor:
    for row in cursor:
        row[row.index("Field1")] = "Your value here"
        # etc.
        cursor.Update(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 17:12:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpro-3-1-2-how-to-search-and-update-fields-in/m-p/1359788#M69392</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2023-12-12T17:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPro 3.1.2 - How to search and update fields in arcpy.da.UpdateCursor using field names and not index?</title>
      <link>https://community.esri.com/t5/python-questions/arcpro-3-1-2-how-to-search-and-update-fields-in/m-p/1359794#M69393</link>
      <description>&lt;P&gt;I use &lt;A href="https://arcpy.wordpress.com/2012/07/12/getting-arcpy-da-rows-back-as-dictionaries/" target="_self"&gt;this little function&lt;/A&gt; to iterate the rows as a dictionary instead of a tuple.&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;</description>
      <pubDate>Tue, 12 Dec 2023 17:20:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpro-3-1-2-how-to-search-and-update-fields-in/m-p/1359794#M69393</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2023-12-12T17:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPro 3.1.2 - How to search and update fields in arcpy.da.UpdateCursor using field names and not index?</title>
      <link>https://community.esri.com/t5/python-questions/arcpro-3-1-2-how-to-search-and-update-fields-in/m-p/1360192#M69403</link>
      <description>&lt;P&gt;There are a couple of very good answers here already to help you. If you are taking multiple field names in one parameter from a tool you can use the below to get them as a list of field names and then supply into your UpdateCursor.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;## get multiple field names from user input
in_flds = arcpy.GetParameterAsText(0)

## split into a list of field names
in_flds = in_flds.replace("'", "").split(";")

with arcpy.da.UpdateCursor(in_table, in_flds) as cursor:
    ...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can also factor in either from&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/458875"&gt;@AlfredBaldenweck&lt;/a&gt;&amp;nbsp;or&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;&amp;nbsp;to achieve your updates.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2023 10:14:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpro-3-1-2-how-to-search-and-update-fields-in/m-p/1360192#M69403</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2023-12-13T10:14:55Z</dc:date>
    </item>
  </channel>
</rss>

