<?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: Code will not update cursor value in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/code-will-not-update-cursor-value/m-p/413764#M32579</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yeah, I tried "GRIDCODE" as well as the first argument/parameter, but that didn't work either.&amp;nbsp; Not getting any errors, but the cursor is not updating.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 19 Oct 2011 16:23:34 GMT</pubDate>
    <dc:creator>LindaVasil</dc:creator>
    <dc:date>2011-10-19T16:23:34Z</dc:date>
    <item>
      <title>Code will not update cursor value</title>
      <link>https://community.esri.com/t5/python-questions/code-will-not-update-cursor-value/m-p/413762#M32577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I wrote this somewhat simple script that is suppose to change and update polygon GRIDCODES based some rules.&amp;nbsp; The shapefile is reclassified into likelihood of conversion.&amp;nbsp; So the code is set up to get the GRIDCODE value of all adjacent polygons to the cursor polygon.&amp;nbsp; I put these in a list, sort the codes, and assign a variable to the largest value.&amp;nbsp; I then count the number of times this large variable occurs.&amp;nbsp; If it occured 4 or more times and the large value is greater than the cursor gridcode, I want to update the cursor to the large value.&amp;nbsp; Fore some reason, it's doing almost everything I ask, but updating the values if it passing the if statement.&amp;nbsp; Can anyone see where I'm going wrong?&amp;nbsp; Thanks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's the code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import sys, string, os, arcpy

arcpy.AddToolbox("C:/Program Files (x86)/ArcGIS/Desktop10.0/ArcToolbox/Toolboxes/Data Management Tools.tbx")

ifc = sys.argv[1]

ily = "Input Layer"

desc = arcpy.Describe(ifc)

arcpy.MakeFeatureLayer_management(ifc,ily, "", "", "")
oid = desc.OIDFieldName

cursor = arcpy.UpdateCursor(ifc)
row = cursor.next()

while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; ci = row.getValue(oid)
&amp;nbsp;&amp;nbsp;&amp;nbsp; fi = row.getValue("GRIDCODE")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("The current GridCode value of this polygon is " + str(fi))
&amp;nbsp;&amp;nbsp;&amp;nbsp; sql = oid + " = " + str(ci)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(ily,"NEW_SELECTION",sql)
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = arcpy.SelectLayerByLocation_management(ily, "BOUNDARY_TOUCHES", ily, "", "NEW_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp; uc = arcpy.UpdateCursor(result)
&amp;nbsp;&amp;nbsp;&amp;nbsp; gridList = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in uc:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; item = row.getValue("GRIDCODE")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gridList.append(item)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gridList.sort()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LR_Value = gridList[-1]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tie_LR = gridList.count(LR_Value)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if tie_LR &amp;gt;= 4 and tie_LR &amp;gt; fi:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(fi, LR_Value)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uc.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("The large value in list is " + str(LR_Value))
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("This is the tie value " + str(tie_LR))
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("This is the updated value " + str(fi))
&amp;nbsp;&amp;nbsp;&amp;nbsp; #arcpy.AddMessage(gridList)
&amp;nbsp;&amp;nbsp;&amp;nbsp; del row
&amp;nbsp;&amp;nbsp;&amp;nbsp; del uc
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = cursor.next()
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2011 14:40:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-will-not-update-cursor-value/m-p/413762#M32577</guid>
      <dc:creator>LindaVasil</dc:creator>
      <dc:date>2011-10-19T14:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: Code will not update cursor value</title>
      <link>https://community.esri.com/t5/python-questions/code-will-not-update-cursor-value/m-p/413763#M32578</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If I'm reading this correctly, the first parameter of your setValue is fi, which is set to a GRIDCODE value.&amp;nbsp; The first parameter should be a field name, I believe, probably "GRIDCODE".&amp;nbsp; That may be causing the trouble.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2011 15:06:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-will-not-update-cursor-value/m-p/413763#M32578</guid>
      <dc:creator>ChristopherStorer</dc:creator>
      <dc:date>2011-10-19T15:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: Code will not update cursor value</title>
      <link>https://community.esri.com/t5/python-questions/code-will-not-update-cursor-value/m-p/413764#M32579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yeah, I tried "GRIDCODE" as well as the first argument/parameter, but that didn't work either.&amp;nbsp; Not getting any errors, but the cursor is not updating.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2011 16:23:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-will-not-update-cursor-value/m-p/413764#M32579</guid>
      <dc:creator>LindaVasil</dc:creator>
      <dc:date>2011-10-19T16:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: Code will not update cursor value</title>
      <link>https://community.esri.com/t5/python-questions/code-will-not-update-cursor-value/m-p/413765#M32580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Can you prove that it's getting to the if statement?&amp;nbsp; I'm curious how many rows the loops is iterating through.&amp;nbsp; That will help pinpoint the error.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2011 16:45:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-will-not-update-cursor-value/m-p/413765#M32580</guid>
      <dc:creator>ChristopherStorer</dc:creator>
      <dc:date>2011-10-19T16:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: Code will not update cursor value</title>
      <link>https://community.esri.com/t5/python-questions/code-will-not-update-cursor-value/m-p/413766#M32581</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It is making it's way into the if statement.&amp;nbsp; I put an "addmessage" statement in the if statement to print LR_Value and fi.&amp;nbsp; It is printing those two values along with the first addmessage statement in the while loop.&amp;nbsp; It goes through the loop multiple times, I usually cancel the operation once I get enough to analyze if the cursor is updating or not.&amp;nbsp; I did correct the if statement, instead of tie_LR &amp;gt; fi, it should be LR_Value &amp;gt; fi.&amp;nbsp; Here's the code now.&amp;nbsp; Still not updating though...weird.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import sys, string, os, arcpy

arcpy.AddToolbox("C:/Program Files (x86)/ArcGIS/Desktop10.0/ArcToolbox/Toolboxes/Data Management Tools.tbx")

ifc = sys.argv[1]

ily = "Input Layer"

desc = arcpy.Describe(ifc)

arcpy.MakeFeatureLayer_management(ifc,ily, "", "", "")
oid = desc.OIDFieldName

cursor = arcpy.UpdateCursor(ifc)
row = cursor.next()

while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; ci = row.getValue(oid)
&amp;nbsp;&amp;nbsp;&amp;nbsp; fi = row.getValue("GRIDCODE")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("The current GridCode value of this polygon is " + str(fi))
&amp;nbsp;&amp;nbsp;&amp;nbsp; sql = oid + " = " + str(ci)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(ily,"NEW_SELECTION",sql)
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = arcpy.SelectLayerByLocation_management(ily, "BOUNDARY_TOUCHES", ily, "", "NEW_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp; uc = arcpy.UpdateCursor(result)
&amp;nbsp;&amp;nbsp;&amp;nbsp; gridList = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in uc:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; item = row.getValue("GRIDCODE")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gridList.append(item)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gridList.sort()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LR_Value = gridList[-1]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tie_LR = gridList.count(LR_Value)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if tie_LR &amp;gt;= 4 and LR_Value &amp;gt; fi:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("GRIDCODE", LR_Value)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uc.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(LR_Value)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(fi)
&amp;nbsp;&amp;nbsp;&amp;nbsp; #arcpy.AddMessage(gridList)
&amp;nbsp;&amp;nbsp;&amp;nbsp; #arcpy.AddMessage("The large value in list is " + str(LR_Value))
&amp;nbsp;&amp;nbsp;&amp;nbsp; #arcpy.AddMessage("This is the tie value " + str(tie_LR))
&amp;nbsp;&amp;nbsp;&amp;nbsp; #arcpy.AddMessage("This is the updated value " + str(fi))
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; del row
&amp;nbsp;&amp;nbsp;&amp;nbsp; del uc
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = cursor.next()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:45:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-will-not-update-cursor-value/m-p/413766#M32581</guid>
      <dc:creator>LindaVasil</dc:creator>
      <dc:date>2021-12-11T18:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: Code will not update cursor value</title>
      <link>https://community.esri.com/t5/python-questions/code-will-not-update-cursor-value/m-p/413767#M32582</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I assume it's getting confused at your use of "row" for both cursors. Change one to something else (e.g. "row2").&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2011 19:58:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/code-will-not-update-cursor-value/m-p/413767#M32582</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2011-10-19T19:58:11Z</dc:date>
    </item>
  </channel>
</rss>

