<?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: UpdateCursor setValue() equivalent for da.UpdateCursor? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/updatecursor-setvalue-equivalent-for-da/m-p/407793#M32108</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Darren, this makes perfect sense.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One challenge I was having was updating a 'lastUpdated' column to the localtime() without passing the 'lastUpdated' field to da.UpdateCursor first.&amp;nbsp; I decided to append the value of localtime() to the end of the values array and 'lastUpdated' to the end of the fields array. It's working beautifully!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 30 Sep 2015 18:31:53 GMT</pubDate>
    <dc:creator>KDeVogelaere</dc:creator>
    <dc:date>2015-09-30T18:31:53Z</dc:date>
    <item>
      <title>UpdateCursor setValue() equivalent for da.UpdateCursor?</title>
      <link>https://community.esri.com/t5/python-questions/updatecursor-setvalue-equivalent-for-da/m-p/407788#M32103</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can I rewrite the Python code below using &lt;STRONG&gt;da.UpdateCursor &lt;/STRONG&gt;?&amp;nbsp; I could not find an equivalent setValue() method for da.UpdateCursor to make the changes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;i = 0&lt;BR /&gt; fields= ['LastName','FirstName']&lt;BR /&gt; values= ['Jensen','Parky']&lt;P&gt;&lt;/P&gt;rows = arcpy.UpdateCursor(table, where)&lt;BR /&gt; for row in rows:&lt;BR /&gt; while (i &amp;lt; len(fields)):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(fields&lt;I&gt;, values&lt;I&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i += 1&lt;P&gt;&lt;/P&gt;rows.updateRow(row)&lt;BR /&gt;del rows, row&lt;/I&gt;&lt;/I&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Are there any arcpy methods to return the index of tableName.fieldName that we can plug into row[index] when using da.UpdateCursor?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Katie&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2015 16:10:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updatecursor-setvalue-equivalent-for-da/m-p/407788#M32103</guid>
      <dc:creator>KDeVogelaere</dc:creator>
      <dc:date>2015-09-30T16:10:54Z</dc:date>
    </item>
    <item>
      <title>Re: UpdateCursor setValue() equivalent for da.UpdateCursor?</title>
      <link>https://community.esri.com/t5/python-questions/updatecursor-setvalue-equivalent-for-da/m-p/407789#M32104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy


i = 0
fields = ["LastName", "FirstName"]
values = ["Jensen", "Parky"]


# Option A
with arcpy.da.UpdateCursor(table, fields, where) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (i &amp;lt; len(fields)):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row&lt;I&gt; = values&lt;I&gt;&lt;/I&gt;&lt;/I&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i+=1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i=0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
# Option B
with arcpy.da.UpdateCursor(table, fields, where) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for i,value in enumerate(values):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row&lt;I&gt; = value&lt;/I&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:32:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updatecursor-setvalue-equivalent-for-da/m-p/407789#M32104</guid>
      <dc:creator>FreddieGibson</dc:creator>
      <dc:date>2021-12-11T18:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: UpdateCursor setValue() equivalent for da.UpdateCursor?</title>
      <link>https://community.esri.com/t5/python-questions/updatecursor-setvalue-equivalent-for-da/m-p/407790#M32105</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Freddie, what if fields[0] and fields[1] are not the first and second fields in the attribute table?&amp;nbsp; Will this still work?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example,&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid #c6c6c6; width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: left; background-color: #f2f2f2; color: #505050; padding: 6px;" valign="middle"&gt;&lt;STRONG&gt;OBJECTID&lt;BR /&gt;&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: left; background-color: #f2f2f2; color: #505050; padding: 6px;" valign="middle"&gt;&lt;STRONG&gt;FirstName&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: left; background-color: #f2f2f2; color: #505050; padding: 6px;" valign="middle"&gt;&lt;STRONG&gt;LastName&lt;BR /&gt;&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 6px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 6px;"&gt;Jane&lt;/TD&gt;&lt;TD style="padding: 6px;"&gt;Doe&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #f6f6f6;"&gt;&lt;STRONG&gt;row&lt;I&gt; = value&lt;/I&gt;&lt;/STRONG&gt;&lt;I&gt; &lt;/I&gt;&lt;/SPAN&gt; // i = 0&amp;nbsp; // row[0] is OBJECTID&amp;nbsp; // fields[0] is FirstName&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2015 17:54:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updatecursor-setvalue-equivalent-for-da/m-p/407790#M32105</guid>
      <dc:creator>KDeVogelaere</dc:creator>
      <dc:date>2015-09-30T17:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: UpdateCursor setValue() equivalent for da.UpdateCursor?</title>
      <link>https://community.esri.com/t5/python-questions/updatecursor-setvalue-equivalent-for-da/m-p/407791#M32106</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;fields[0] and fields[1] correspond to &lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;fields = [&lt;/SPAN&gt;&lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue;"&gt;"LastName"&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;, &lt;/SPAN&gt;&lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue;"&gt;"FirstName"&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;] &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif;"&gt;&lt;A href="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-data-access/updatecursor-class.htm" title="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-data-access/updatecursor-class.htm"&gt;UpdateCursor—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2015 17:58:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updatecursor-setvalue-equivalent-for-da/m-p/407791#M32106</guid>
      <dc:creator>WesMiller</dc:creator>
      <dc:date>2015-09-30T17:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: UpdateCursor setValue() equivalent for da.UpdateCursor?</title>
      <link>https://community.esri.com/t5/python-questions/updatecursor-setvalue-equivalent-for-da/m-p/407792#M32107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You decide which fields to include in the cursor. In doing so, you also decide the order of the fields in the cursor. Alternatively, you can include all fields by using '*', which will return all fields in the order found in the attribute table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Consider a feature class with many fields, in any order, but you are interested in only "name", "age", and "address".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;with arcpy.da.UpdateCursor("myFeatureClass",["name","age","address"]) as cursor: # you set cursor field order here
&amp;nbsp; for row in cursor: # loop through each row in the cursor
&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[0] # name
&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[1] # age
&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[2] # address&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;vs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;with arcpy.da.UpdateCursor("myFeatureClass",["name","address","age"]) as cursor: # you set cursor field order here
 for row in cursor: # loop through each row in the cursor
&amp;nbsp;&amp;nbsp; print row[0] # name
&amp;nbsp;&amp;nbsp; print row[1] # address
&amp;nbsp;&amp;nbsp; print row[2] # age&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:32:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updatecursor-setvalue-equivalent-for-da/m-p/407792#M32107</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T18:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: UpdateCursor setValue() equivalent for da.UpdateCursor?</title>
      <link>https://community.esri.com/t5/python-questions/updatecursor-setvalue-equivalent-for-da/m-p/407793#M32108</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Darren, this makes perfect sense.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One challenge I was having was updating a 'lastUpdated' column to the localtime() without passing the 'lastUpdated' field to da.UpdateCursor first.&amp;nbsp; I decided to append the value of localtime() to the end of the values array and 'lastUpdated' to the end of the fields array. It's working beautifully!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2015 18:31:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updatecursor-setvalue-equivalent-for-da/m-p/407793#M32108</guid>
      <dc:creator>KDeVogelaere</dc:creator>
      <dc:date>2015-09-30T18:31:53Z</dc:date>
    </item>
  </channel>
</rss>

