<?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: StopIteration: iteration not started (Python 2.7) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/stopiteration-iteration-not-started-python-2-7/m-p/1250446#M66617</link>
    <description>&lt;P&gt;You iterate over the csv file, but arcpy expects you to iterate over the UpdateCursor.&lt;/P&gt;&lt;P&gt;Are you sure UpdateCursor is what you need? It seems like you could actually want InsertCursor.&lt;/P&gt;</description>
    <pubDate>Mon, 23 Jan 2023 16:55:11 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2023-01-23T16:55:11Z</dc:date>
    <item>
      <title>StopIteration: iteration not started (Python 2.7)</title>
      <link>https://community.esri.com/t5/python-questions/stopiteration-iteration-not-started-python-2-7/m-p/1250437#M66616</link>
      <description>&lt;P&gt;I need to add about 500 values (street names) to a domain called streetxx. The street names are in a csv file called streetname.csv. I'm using AarcMap 10.8.2. My code is very simple yet I'm getting a StopIteration error. What am I doing wrong? Thanks for the help in advance.&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import csv&lt;/P&gt;&lt;P&gt;# Set the path to the CSV file and the geodatabase&lt;BR /&gt;csv_file = r"J:\OMS_Upgrade\Water\streetname.csv"&lt;BR /&gt;gdb = r"J:\OMS_Upgrade\OMSTest.mdb"&lt;/P&gt;&lt;P&gt;# Set the name of the feature class and field to be updated&lt;BR /&gt;fc = "Water_Mains"&lt;BR /&gt;field = "Streetxx"&lt;/P&gt;&lt;P&gt;# Use the arcpy.da.UpdateCursor() method to update the feature class&lt;BR /&gt;with arcpy.da.UpdateCursor(gdb + "\\" + fc, [field]) as cursor:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; # Open the CSV file and read the values&lt;BR /&gt;&amp;nbsp; &amp;nbsp; with open(csv_file, "r") as f:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; reader = csv.reader(f)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Skip the header row&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; next(reader)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Iterate over the rows in the CSV file&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for row in reader:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Update the field with the value from the CSV file&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cursor.updateRow([row[0]])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the error message:&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "J:\OMS_Upgrade\Scripts\Update_Domain.py", line 23, in &amp;lt;module&amp;gt;&lt;BR /&gt;cursor.updateRow([row[0]])&lt;BR /&gt;StopIteration: iteration not started&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 16:44:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stopiteration-iteration-not-started-python-2-7/m-p/1250437#M66616</guid>
      <dc:creator>NinaBaksh</dc:creator>
      <dc:date>2023-01-23T16:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: StopIteration: iteration not started (Python 2.7)</title>
      <link>https://community.esri.com/t5/python-questions/stopiteration-iteration-not-started-python-2-7/m-p/1250446#M66617</link>
      <description>&lt;P&gt;You iterate over the csv file, but arcpy expects you to iterate over the UpdateCursor.&lt;/P&gt;&lt;P&gt;Are you sure UpdateCursor is what you need? It seems like you could actually want InsertCursor.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 16:55:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stopiteration-iteration-not-started-python-2-7/m-p/1250446#M66617</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-01-23T16:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: StopIteration: iteration not started (Python 2.7)</title>
      <link>https://community.esri.com/t5/python-questions/stopiteration-iteration-not-started-python-2-7/m-p/1250461#M66618</link>
      <description>&lt;P&gt;Johannes, my day is now improving. Thank you for helping me with this.&lt;/P&gt;&lt;P&gt;I replaced UpdateCursor with InsertCursor and there is no longer an error.&lt;/P&gt;&lt;P&gt;However, the Coded Values did not get updated. I've attached an image of 3 coded values I entered manually beside my list my streetname.csv&lt;/P&gt;&lt;P&gt;Am I missing a step?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Nina&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 17:45:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stopiteration-iteration-not-started-python-2-7/m-p/1250461#M66618</guid>
      <dc:creator>NinaBaksh</dc:creator>
      <dc:date>2023-01-23T17:45:20Z</dc:date>
    </item>
    <item>
      <title>Re: StopIteration: iteration not started (Python 2.7)</title>
      <link>https://community.esri.com/t5/python-questions/stopiteration-iteration-not-started-python-2-7/m-p/1250483#M66620</link>
      <description>&lt;P&gt;Ah, I somehow missed the part where you say that you want to update the domain.&lt;/P&gt;&lt;P&gt;In ArcGIS, domains are handled differently from tables. Notably here, the arcpy.da.*Cursor classes only work on tables/feature classes, not on domains. To work with domains, you need the tools from the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/an-overview-of-the-domains-toolset.htm" target="_blank" rel="noopener"&gt;Data management/Domains toolset&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something like this should work:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import csv

# set the variables
csv_path = r"G:\ArcGIS\data\streetname.csv"
gdb = r"G:\ArcGIS\projects\Test\Test.gdb"
domain_name = "TestDomain"

# start the csv reader and skip header
with open(csv_path, "r") as csv_file:
    reader = csv.reader(csv_file)
    next(reader)
# loop over the csv rows and write the values into the domain
    for code, description in reader:
        arcpy.management.AddCodedValueToDomain(gdb, domain_name, code, description)&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 23 Jan 2023 18:23:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stopiteration-iteration-not-started-python-2-7/m-p/1250483#M66620</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-01-23T18:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: StopIteration: iteration not started (Python 2.7)</title>
      <link>https://community.esri.com/t5/python-questions/stopiteration-iteration-not-started-python-2-7/m-p/1250580#M66622</link>
      <description>&lt;P&gt;I can't thank you enough Johannes. The above solution works great!&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 21:54:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stopiteration-iteration-not-started-python-2-7/m-p/1250580#M66622</guid>
      <dc:creator>NinaBaksh</dc:creator>
      <dc:date>2023-01-23T21:54:14Z</dc:date>
    </item>
  </channel>
</rss>

