<?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: Iterate through a field? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/iterate-through-a-field/m-p/635404#M49485</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm a little confused as to what you are trying to accomplish exactly. Are you trying to access the geometry component of the row? Or just modify the attribute values?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This link should give you all you need to access the geometry of the row features.&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Reading_geometries/002z0000001t000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Reading_geometries/002z0000001t000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you just want attributes of the row, this will get you their values&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;rows = arcpy.UpdateCursor(layer)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fields:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row.getValue(field.name)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 03:01:28 GMT</pubDate>
    <dc:creator>MathewCoyle</dc:creator>
    <dc:date>2021-12-12T03:01:28Z</dc:date>
    <item>
      <title>Iterate through a field?</title>
      <link>https://community.esri.com/t5/python-questions/iterate-through-a-field/m-p/635403#M49484</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've written code that allows me to list adjacent neighbors to a new field.&amp;nbsp; I did this to pre-process a land use file because this task usually takes a long time to run.&amp;nbsp; 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.&amp;nbsp; When I run the code, I get an error that TypeError: 'Field' object is not iterable&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anyone have any suggestions of how to work around this?&amp;nbsp; 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.&amp;nbsp; I only want to find the neighbors once, then update land use codes if conditions are right.&amp;nbsp; Do I have to create a new field for each neighbor?&amp;nbsp; Here's the code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import sys, string, os, arcpy&amp;nbsp; arcpy.CheckOutExtension("Spatial")&amp;nbsp; ifc = sys.argv[1]&amp;nbsp; ily = "Input Layer"&amp;nbsp; desc = arcpy.Describe(ifc) arcpy.MakeFeatureLayer_management(ifc, ily, "", "", "") oid = desc.OIDFieldName&amp;nbsp; uc = arcpy.UpdateCursor(ifc) line = uc.next()&amp;nbsp; fields = arcpy.ListFields(ifc) for line in uc: &amp;nbsp;&amp;nbsp;&amp;nbsp; ci = line.getValue(oid) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("The current FID value is " + str(ci)) &amp;nbsp;&amp;nbsp;&amp;nbsp; fi = line.getValue("GRID_CODE") &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("The current GridCode value is " + str(fi)) &amp;nbsp;&amp;nbsp;&amp;nbsp; OIDList = []&amp;nbsp; #Find the Neighbors field and just print the list for each point for now &amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fields: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if field.name == "Neighbors": &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for items in field: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print items&amp;nbsp; del line del uc&lt;/PRE&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for any help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Feb 2012 19:49:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-through-a-field/m-p/635403#M49484</guid>
      <dc:creator>LindaVasil</dc:creator>
      <dc:date>2012-02-07T19:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through a field?</title>
      <link>https://community.esri.com/t5/python-questions/iterate-through-a-field/m-p/635404#M49485</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm a little confused as to what you are trying to accomplish exactly. Are you trying to access the geometry component of the row? Or just modify the attribute values?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This link should give you all you need to access the geometry of the row features.&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Reading_geometries/002z0000001t000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Reading_geometries/002z0000001t000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you just want attributes of the row, this will get you their values&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;rows = arcpy.UpdateCursor(layer)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fields:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row.getValue(field.name)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:01:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-through-a-field/m-p/635404#M49485</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-12T03:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through a field?</title>
      <link>https://community.esri.com/t5/python-questions/iterate-through-a-field/m-p/635405#M49486</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sorry I wasn't too clear.&amp;nbsp; The main goal I'm trying to accomplish is cellular automata on a land use file.&amp;nbsp; I converted a raster to a point file, selected the adjacent neighbors and then I put a conditional statement in the cellular automata code that the cursor point will update to a different land use when the conditions are met.&amp;nbsp; I was using select by location to find the adjacent neighbor, but it was making the processing time into the days.&amp;nbsp; Since I run this land use simulation over and over again, I wanted to shorten the processing time.&amp;nbsp; I did this by first writing a code that selects the adjacent neighbors and putting the selection in a new field.&amp;nbsp; So I have a list of neighbors within one field.&amp;nbsp; This is the pre-processing code that takes hours to run...but that's ok because I only need it to run one time.&amp;nbsp; Then I'm trying to write another code that looks specifically at the list within the neighbors field and gives me the grid code for each neighbor.&amp;nbsp; That's where I'm running into problems because fields apparently cannot be iterated.&amp;nbsp; I will try playing around with your snippet, but I'm trying to find a list within a field not the whole row.&amp;nbsp; Maybe I can modify it, but if you have any suggestions after the further clarifications I would appreciate it!&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, 08 Feb 2012 12:49:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-through-a-field/m-p/635405#M49486</guid>
      <dc:creator>LindaVasil</dc:creator>
      <dc:date>2012-02-08T12:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through a field?</title>
      <link>https://community.esri.com/t5/python-questions/iterate-through-a-field/m-p/635406#M49487</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Feb 2012 13:40:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-through-a-field/m-p/635406#M49487</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-02-08T13:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through a field?</title>
      <link>https://community.esri.com/t5/python-questions/iterate-through-a-field/m-p/635407#M49488</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;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.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The list of neighbors is stored as a string with a semicolon between FIDs.&amp;nbsp; I've attached a snapshot of the attribute table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]11994[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried the following using cursors&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
uc = arcpy.UpdateCursor(ifc)
line = uc.next()

fields = arcpy.ListFields(ifc)
for line in uc:
&amp;nbsp;&amp;nbsp;&amp;nbsp; ci = line.getValue(oid)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("The current FID value is " + str(ci))
&amp;nbsp;&amp;nbsp;&amp;nbsp; fi = line.getValue("GRID_CODE")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("The current GridCode value is " + str(fi))
&amp;nbsp;&amp;nbsp;&amp;nbsp; OIDList = []

#Find the Neighbors field and just print the list of ids for each point for now
&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fields:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if field.name == "Neighbors":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for item in field:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; line.getValue(item)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print item

del line
del uc
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I get this error when I run the code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; exec codeObject in __main__.__dict__&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Users\Flash\Documents\School\CA\ListFields.py", line 27, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for item in field:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TypeError: 'Field' object is not iterable&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I appreciate any help.&amp;nbsp; I've almost completed this using strictly python, but I would rather do it in ArcGIS to eliminate constantly loading up text files.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:01:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-through-a-field/m-p/635407#M49488</guid>
      <dc:creator>LindaVasil</dc:creator>
      <dc:date>2021-12-12T03:01:31Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through a field?</title>
      <link>https://community.esri.com/t5/python-questions/iterate-through-a-field/m-p/635408#M49489</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;hi Linda,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
#Find the Neighbors field and just print the list of ids for each point for now
&amp;nbsp;&amp;nbsp;&amp;nbsp; nbList = [int(x) for x in line.Neighbors.split(";")]&amp;nbsp; # this should split all the ids of the current item(i.e. row) into a list, and convert the ids from string to integer
&amp;nbsp;&amp;nbsp;&amp;nbsp; for nb in nbList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print nb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # print each neighbor id

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;hope this helps!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:01:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-through-a-field/m-p/635408#M49489</guid>
      <dc:creator>RaphaelR</dc:creator>
      <dc:date>2021-12-12T03:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through a field?</title>
      <link>https://community.esri.com/t5/python-questions/iterate-through-a-field/m-p/635409#M49490</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;hi Linda,&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#Find the Neighbors field and just print the list of ids for each point for now &amp;nbsp;&amp;nbsp;&amp;nbsp; nbList = [int(x) for x in line.Neighbors.split(";")]&amp;nbsp; # this should split all the ids of the current item(i.e. row) into a list, and convert the ids from string to integer &amp;nbsp;&amp;nbsp;&amp;nbsp; for nb in nbList: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print nb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # print each neighbor id &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;hope this helps!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks very much!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Feb 2012 15:12:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-through-a-field/m-p/635409#M49490</guid>
      <dc:creator>LindaVasil</dc:creator>
      <dc:date>2012-02-16T15:12:07Z</dc:date>
    </item>
  </channel>
</rss>

