AnsweredAssumed Answered

Iterate through a field?

Question asked by ljvasil on Feb 7, 2012
Latest reply on Feb 16, 2012 by ljvasil
Hi all,

I've written code that allows me to list adjacent neighbors to a new field.  I did this to pre-process a land use file because this task usually takes a long time to run.  What I would like to do with the new processed file that has an added field called "Neighbors" is to pull out each of the items (FID values) in the field, get the GRID_CODE associated with each FID and apply some rules to each point.  When I run the code, I get an error that TypeError: 'Field' object is not iterable

Does anyone have any suggestions of how to work around this?  I pulled out the Select by Feature and Select by Location code out of my main cellular automata processing code because it takes hours for the select by location command to run.  I only want to find the neighbors once, then update land use codes if conditions are right.  Do I have to create a new field for each neighbor?  Here's the code:

import sys, string, os, arcpy  arcpy.CheckOutExtension("Spatial")  ifc = sys.argv[1]  ily = "Input Layer"  desc = arcpy.Describe(ifc) arcpy.MakeFeatureLayer_management(ifc, ily, "", "", "") oid = desc.OIDFieldName  uc = arcpy.UpdateCursor(ifc) line = uc.next()  fields = arcpy.ListFields(ifc) for line in uc:     ci = line.getValue(oid)     arcpy.AddMessage("The current FID value is " + str(ci))     fi = line.getValue("GRID_CODE")     arcpy.AddMessage("The current GridCode value is " + str(fi))     OIDList = []  #Find the Neighbors field and just print the list for each point for now     for field in fields:         if field.name == "Neighbors":             for items in field:                 print items  del line del uc
 

Thanks for any help!

Outcomes