<?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: The script does not work in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/the-script-does-not-work/m-p/1031335#M60159</link>
    <description>&lt;P&gt;my code prints the ID code of the line in which the value does not match the domain values&lt;/P&gt;</description>
    <pubDate>Sun, 28 Feb 2021 16:10:03 GMT</pubDate>
    <dc:creator>Sergey_Grechkin</dc:creator>
    <dc:date>2021-02-28T16:10:03Z</dc:date>
    <item>
      <title>The script does not work</title>
      <link>https://community.esri.com/t5/python-questions/the-script-does-not-work/m-p/1031329#M60154</link>
      <description>&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b"&gt;&lt;SPAN&gt;I'm trying to write a script that will check a column for data compliance with domain values&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b"&gt;&lt;SPAN&gt;If the data does not match, then the column name and row identification number are printed &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fc = 'D:\Arcgis\New Personal Geodatabase.mdb\TEST'
domain_2 = arcpy.da.ListDomains("D:\Arcgis\New Personal Geodatabase.mdb")
field_1 = 'ID_COD'
fields = arcpy.ListFields(fc)
cursor = arcpy.SearchCursor(fc)

for field in fields:
    if field.domain:
        print field.name
        for domain in domain_2:
            if field.domain == domain.name:
                for val in domain.codedValues.keys():
                    a=set()
                    a.add(val)
                    for row in cursor:
                        b=row.getValue(field.name)
                        if b not in a:
                            print (row.getValue(field_1))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b"&gt;&lt;SPAN&gt;But for some reason, the script does not work correctly: the first column shows all erroneously filled cells and all the rest only the column name:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b"&gt;&lt;SPAN&gt;STATUS #column name&lt;BR /&gt;1111111 #line identification number&amp;nbsp;&lt;BR /&gt;2222222 #line identification number&amp;nbsp;&lt;BR /&gt;COMPANY_MANAGER&lt;BR /&gt;COMPANY&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b"&gt;&lt;SPAN&gt;Help find the error &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Feb 2021 16:22:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/the-script-does-not-work/m-p/1031329#M60154</guid>
      <dc:creator>Sergey_Grechkin</dc:creator>
      <dc:date>2021-02-28T16:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: The script does not work</title>
      <link>https://community.esri.com/t5/python-questions/the-script-does-not-work/m-p/1031331#M60155</link>
      <description>&lt;P&gt;You are using the original ArcPy cursors.&amp;nbsp; I encourage you to use the ArcPy Data Access cursors which are much more efficient and Pythonic in form:&amp;nbsp; &lt;A href="https://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-data-access/searchcursor-class.htm" target="_self"&gt;SearchCursor - Help | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;You are checking existing record values for compliance with existing domain values.&amp;nbsp; What do you want to do if there are non-compliant record values?&amp;nbsp; Right now your code appears to be just be printing an identifier value, ID_COD.&lt;/P&gt;</description>
      <pubDate>Sun, 28 Feb 2021 15:45:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/the-script-does-not-work/m-p/1031331#M60155</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-02-28T15:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: The script does not work</title>
      <link>https://community.esri.com/t5/python-questions/the-script-does-not-work/m-p/1031332#M60156</link>
      <description>&lt;P&gt;I've not had great experience of this so I may be wrong, but I believe that because the cursor was instantiated outside of the loop, it is effectively stuck at the end of it's iteration.&lt;/P&gt;&lt;P&gt;Possibly adding cursor.reset() will do the trick.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fc = 'D:\Arcgis\New Personal Geodatabase.mdb\TEST'
domain_2 = arcpy.da.ListDomains("D:\Arcgis\New Personal Geodatabase.mdb")
field_1 = 'ID_COD'
fields = arcpy.ListFields(fc)
cursor = arcpy.SearchCursor(fc)

for field in fields:
    if field.domain:
        print field.name
        for domain in domain_2:
            if field.domain == domain.name:
                for val in domain.codedValues.keys():
                    a=set()
                    a.add(val)
                    for row in cursor:
                        b=row.getValue(field.name)
                        if b not in a:
                            print (row.getValue(field_1))
                    cursor.reset()&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 28 Feb 2021 15:58:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/the-script-does-not-work/m-p/1031332#M60156</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-02-28T15:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: The script does not work</title>
      <link>https://community.esri.com/t5/python-questions/the-script-does-not-work/m-p/1031333#M60157</link>
      <description>&lt;P&gt;You are doing this in arcmap.&amp;nbsp; You should raw encode your file paths since it will cause errors going forward&lt;/P&gt;&lt;LI-CODE lang="python"&gt;f = "D:\Arcgis\New Personal Geodatabase.mdb\TEST"  # --- won't work in ArcGIS Pro
  File "&amp;lt;ipython-input-4-a546e0cc6769&amp;gt;", line 1
    f = "D:\Arcgis\New Personal Geodatabase.mdb\TEST"
       ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 9-10: malformed \N character escape


f = r"D:\Arcgis\New Personal Geodatabase.mdb\TEST" # --- raw encoding&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 28 Feb 2021 15:58:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/the-script-does-not-work/m-p/1031333#M60157</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-02-28T15:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: The script does not work</title>
      <link>https://community.esri.com/t5/python-questions/the-script-does-not-work/m-p/1031334#M60158</link>
      <description>&lt;P&gt;I'd suggest you step through the code with a debugger so you can watch what your variables become and what your code is doing throughout its loops.&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;Since domain_2 is a list, you can use list comprehension to check for equality by changing&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if field.domain:
    print field.name
    for domain in domain_2:
        if field.domain == domain.name:&lt;/LI-CODE&gt;&lt;P&gt;to&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if field.domain in [domain.name for domain in domain_2]:
   print field.name&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Feb 2021 16:08:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/the-script-does-not-work/m-p/1031334#M60158</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-02-28T16:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: The script does not work</title>
      <link>https://community.esri.com/t5/python-questions/the-script-does-not-work/m-p/1031335#M60159</link>
      <description>&lt;P&gt;my code prints the ID code of the line in which the value does not match the domain values&lt;/P&gt;</description>
      <pubDate>Sun, 28 Feb 2021 16:10:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/the-script-does-not-work/m-p/1031335#M60159</guid>
      <dc:creator>Sergey_Grechkin</dc:creator>
      <dc:date>2021-02-28T16:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: The script does not work</title>
      <link>https://community.esri.com/t5/python-questions/the-script-does-not-work/m-p/1031336#M60160</link>
      <description>&lt;P&gt;David you are right &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;cursor = arcpy.SearchCursor(fc)&lt;/P&gt;&lt;P&gt;need to be placed in the body of the loop&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fc = 'D:\Arcgis\New Personal Geodatabase.mdb\TEST'
domain_2 = arcpy.da.ListDomains("D:\Arcgis\New Personal Geodatabase.mdb")
field_1 = 'ID_COD'
fields = arcpy.ListFields(fc)
 
for field in fields:
    if field.domain:
        print field.name
        for domain in domain_2:
            if field.domain == domain.name:
                for val in domain.codedValues.keys():
                    a=set()
                    a.add(val)
                    cursor = arcpy.SearchCursor(fc)
                    for row in cursor:
                        b=row.getValue(field.name)
                        if b not in a:
                            print (row.getValue(field_1))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;P&gt;STATUS&lt;BR /&gt;1111111&lt;BR /&gt;2222222&lt;BR /&gt;COMPANY_MANAGER&lt;BR /&gt;1111111&lt;BR /&gt;33333333&lt;BR /&gt;COMPANY&lt;BR /&gt;2222222&lt;/P&gt;</description>
      <pubDate>Sun, 28 Feb 2021 16:38:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/the-script-does-not-work/m-p/1031336#M60160</guid>
      <dc:creator>Sergey_Grechkin</dc:creator>
      <dc:date>2021-02-28T16:38:18Z</dc:date>
    </item>
  </channel>
</rss>

