<?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: Trying to add rows and update values using arcpy.da.InsertCursor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/trying-to-add-rows-and-update-values-using-arcpy/m-p/160314#M12279</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I cannot help thinking that this script is a tad overelaborate.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Who was the Spanish king who, after the Ptolomaic cosmological system was explained to him,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;remarked that "Had God first consulted him (the king) before building the universe,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;he (the king) would have suggested something very much simpler"?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In any event,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A da search cursor returns a tuple, which is immutable.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You can, though, convert the tupple to a list, using&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;tmpList = list(rowParcel)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, since you know the position of the fsa item in the tupple (now a mutable list),&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;you can update it by index.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;tmpList[fsaIndexPosition] = fsa&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now convert the list back into a tuple:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;newRow = tuple(tmpList)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;... and use the cursor to insert the tuple as a new row:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;inCur.insertRow(newRow)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 05 Nov 2013 17:06:47 GMT</pubDate>
    <dc:creator>markdenil</dc:creator>
    <dc:date>2013-11-05T17:06:47Z</dc:date>
    <item>
      <title>Trying to add rows and update values using arcpy.da.InsertCursor</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-add-rows-and-update-values-using-arcpy/m-p/160313#M12278</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In my code, I am creating duplicate polygons from existing polygons all within the same feature class.&amp;nbsp; I am passing all the attributes from the original polygon to the duplicate.&amp;nbsp; This works fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But what I cannot figure out is how to change one attribute value in the duplicate polygon while using the InsertCursor object that creates the duplicate polygon.&amp;nbsp; If I could get the InsertCursor object to do it (update the one attribute value) while inside the same For loop where the duplicate polygon is created - using inCur.insertRow(rowParcel), then it would make it very easy for me to assign the correct value to the duplicate polygon.&amp;nbsp; In the code below, the fsa variable has the value that needs to be inserted into the duplicate polygon.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy&amp;nbsp; # Set Geoprocessing environments arcpy.env.scratchWorkspace = "F:\\ArcGISServer\\DataProcessing\\Mobile_Parcels\\TestData\\Testing.gdb" arcpy.env.workspace = "F:\\ArcGISServer\\DataProcessing\\Mobile_Parcels\\TestData\\Testing.gdb" arcpy.env.overwriteOutput = True&amp;nbsp;&amp;nbsp; # Add code to generate target address list (dataset) addrList_fc = "F:\\ArcGISServer\\DataProcessing\\Mobile_Parcels\\TestData\\Testing.gdb\\addresspts_LeftOut_tmpSel"&amp;nbsp; # Loop through the address list dataset created above; check for parcel# match against target parcels dataset from earlier script; # create duplicate parcel &amp;amp; populate FULL_ADD targetParcels = "F:\\ArcGISServer\\DataProcessing\\Mobile_Parcels\\TestData\\Testing.gdb\\target_parcels_sample"&amp;nbsp; cursor2 = arcpy.da.SearchCursor(targetParcels, ["ASSESSORSI", "*", "SHAPE@"])&amp;nbsp; ## Maybe use ["ASSESSORSI", "FULL_ADD", "*"] inCur = arcpy.da.InsertCursor(targetParcels, ["ASSESSORSI", "*", "SHAPE@"])&amp;nbsp; # Loop thru the address dataset with arcpy.da.SearchCursor(addrList_fc, ["PARCELNO", "FSA"]) as cursor1:&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; for rowAddr in cursor1: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Grab the address value from address dataset &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fsa = rowAddr[1] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor2.reset() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Loop thru the parcel dataset &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for rowParcel in cursor2: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if rowAddr[0] == rowParcel[0]:&amp;nbsp; # Compare parcel # values for a match &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # If there is a match, use current parcel record to create a duplicate parcel and insert the current address value &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # into the parcels FULL_ADD field (don't know how to accomplish this last part) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inCur.insertRow(rowParcel) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break&amp;nbsp; # and get out of inner For Loop and proceed back to outer For Loop &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #else, continue with the next row in the inner For Loop &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del cursor1, cursor2, inCur, rowParcel, rowAddr print "Script completed"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance for any help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Lee&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Nov 2013 20:08:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-add-rows-and-update-values-using-arcpy/m-p/160313#M12278</guid>
      <dc:creator>LeeBrannon</dc:creator>
      <dc:date>2013-11-04T20:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to add rows and update values using arcpy.da.InsertCursor</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-add-rows-and-update-values-using-arcpy/m-p/160314#M12279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I cannot help thinking that this script is a tad overelaborate.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Who was the Spanish king who, after the Ptolomaic cosmological system was explained to him,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;remarked that "Had God first consulted him (the king) before building the universe,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;he (the king) would have suggested something very much simpler"?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In any event,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A da search cursor returns a tuple, which is immutable.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You can, though, convert the tupple to a list, using&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;tmpList = list(rowParcel)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, since you know the position of the fsa item in the tupple (now a mutable list),&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;you can update it by index.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;tmpList[fsaIndexPosition] = fsa&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now convert the list back into a tuple:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;newRow = tuple(tmpList)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;... and use the cursor to insert the tuple as a new row:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;inCur.insertRow(newRow)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Nov 2013 17:06:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-add-rows-and-update-values-using-arcpy/m-p/160314#M12279</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2013-11-05T17:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to add rows and update values using arcpy.da.InsertCursor</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-add-rows-and-update-values-using-arcpy/m-p/160315#M12280</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Much thanks Mark!!&amp;nbsp; Your coding advice worked perfect!&amp;nbsp; It was exactly what I needed to do.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Final code below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy

# Set Geoprocessing environments
arcpy.env.scratchWorkspace = "F:\\ArcGISServer\\DataProcessing\\Mobile_Parcels\\TestData\\Testing.gdb"
arcpy.env.workspace = "F:\\ArcGISServer\\DataProcessing\\Mobile_Parcels\\TestData\\Testing.gdb"
arcpy.env.overwriteOutput = True


# Add code to generate target address list (dataset).
addrList_fc = "F:\\ArcGISServer\\DataProcessing\\Mobile_Parcels\\TestData\\Testing.gdb\\addresspts_LeftOut_tmpSel"

# Loop through the address list dataset created above; check for parcel# match against target parcels dataset from earlier script;
# create duplicate parcel &amp;amp; populate FULL_ADD
targetParcels = "F:\\ArcGISServer\\DataProcessing\\Mobile_Parcels\\TestData\\Testing.gdb\\target_parcels_sample"

cursor2 = arcpy.da.SearchCursor(targetParcels, ["ASSESSORSI", "*", "SHAPE@"])
inCur = arcpy.da.InsertCursor(targetParcels, ["ASSESSORSI", "*", "SHAPE@"])

# Loop thru the address dataset
with arcpy.da.SearchCursor(addrList_fc, ["PARCELNO", "FSA"]) as cursor1:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for rowAddr in cursor1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Grab the address value from address dataset
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fsa = rowAddr[1]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor2.reset()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Loop thru the parcel dataset
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for rowParcel in cursor2:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if rowAddr[0] == rowParcel[0]:&amp;nbsp; # Compare parcel # values for a match
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # If there is a match, use current parcel record to create a duplicate parcel and insert the current address value
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # into the parcels FULL_ADD field.

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Convert the row tuple to a list so values can be changed
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tmpList = list(rowParcel)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Update the situs address value in the list
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tmpList[11] = fsa
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Now convert the list back into a tuple
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dupRow = tuple(tmpList)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inCur.insertRow(dupRow)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break&amp;nbsp; # and get out of inner For Loop and proceed back to outer For Loop
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #else, continue with the next row in the inner For Loop

del cursor1, cursor2, inCur, rowParcel, rowAddr
print "Script completed"
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Lee&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:26:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-add-rows-and-update-values-using-arcpy/m-p/160315#M12280</guid>
      <dc:creator>LeeBrannon</dc:creator>
      <dc:date>2021-12-11T08:26:44Z</dc:date>
    </item>
  </channel>
</rss>

