I think the problem is that you are using the same variable name 'row' for the inner loop. There also seems to be an indentation issue. Use
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)
arcpy.SelectLayerByAttribute_management(ily,"NEW_SELECTION",sql)
result = arcpy.SelectLayerByLocation_management(ily, "BOUNDARY_TOUCHES", ily, "", "NEW_SELECTION")
uc = arcpy.UpdateCursor(result)
gridList = sorted(subrow.getValue("GRIDCODE") for subrow in uc)
LR_Value = gridList[-1]
tie_LR = gridList.count(LR_Value)
if tie_LR >= 4 and LR_Value > fi:
row.setValue("GRIDCODE", LR_Value)
uc.updateRow(row)
arcpy.AddMessage(LR_Value)
arcpy.AddMessage(fi)
del row
del uc
row = cursor.next() Edit: I can't test your code, so...
Gribouillis
Posting Maven
Moderator
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691