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
Solved! Go to Solution.
hi Linda,
as the error states, you can´t iterate the field itself. you have to get its content into a list first, then you can iterate over each item.#Find the Neighbors field and just print the list of ids for each point for now nbList = [int(x) for x in line.Neighbors.split(";")] # this should split all the ids of the current item(i.e. row) into a list, and convert the ids from string to integer for nb in nbList: print nb # print each neighbor id
hope this helps!
rows = arcpy.UpdateCursor(layer) for row in rows: for field in fields: print row.getValue(field.name)
Alright I think I understand now. How is your list of neighbours stored in the field? String of IDs? If you could post an example of the field you are trying to access that may help.
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 of ids for each point for now for field in fields: if field.name == "Neighbors": for item in field: line.getValue(item) print item del line del uc
#Find the Neighbors field and just print the list of ids for each point for now nbList = [int(x) for x in line.Neighbors.split(";")] # this should split all the ids of the current item(i.e. row) into a list, and convert the ids from string to integer for nb in nbList: print nb # print each neighbor id
hi Linda,
as the error states, you can´t iterate the field itself. you have to get its content into a list first, then you can iterate over each item.#Find the Neighbors field and just print the list of ids for each point for now nbList = [int(x) for x in line.Neighbors.split(";")] # this should split all the ids of the current item(i.e. row) into a list, and convert the ids from string to integer for nb in nbList: print nb # print each neighbor id
hope this helps!