Code will not update cursor value

Discussion created by ljvasil on Oct 19, 2011
Latest reply on Oct 19, 2011 by dkwiens
Hi all,

I wrote this somewhat simple script that is suppose to change and update polygon GRIDCODES based some rules.  The shapefile is reclassified into likelihood of conversion.  So the code is set up to get the GRIDCODE value of all adjacent polygons to the cursor polygon.  I put these in a list, sort the codes, and assign a variable to the largest value.  I then count the number of times this large variable occurs.  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.  Fore some reason, it's doing almost everything I ask, but updating the values if it passing the if statement.  Can anyone see where I'm going wrong?  Thanks.

Here's the code:

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:
    ci = row.getValue(oid)
    fi = row.getValue("GRIDCODE")
    arcpy.AddMessage("The current GridCode value of this polygon is " + str(fi))
    sql = oid + " = " + str(ci)
    result = arcpy.SelectLayerByLocation_management(ily, "BOUNDARY_TOUCHES", ily, "", "NEW_SELECTION")
    uc = arcpy.UpdateCursor(result)
    gridList = []
    for row in uc:
        item = row.getValue("GRIDCODE")
        LR_Value = gridList[-1]
        tie_LR = gridList.count(LR_Value)
        if tie_LR >= 4 and tie_LR > fi:
            row.setValue(fi, LR_Value)
    arcpy.AddMessage("The large value in list is " + str(LR_Value))
    arcpy.AddMessage("This is the tie value " + str(tie_LR))
    arcpy.AddMessage("This is the updated value " + str(fi))
    del row
    del uc
    row = cursor.next()