<?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: Comparing values in an Access table with filenames of existing GDB's in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/comparing-values-in-an-access-table-with-filenames/m-p/676494#M52385</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Your second cursor overwrite and destroys the first one. Your loops should be for loops instead. Don't complicate the queries unnecearily. Take advantage of python's alternative quoting syntaxes. And use format strings.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
# Untested, fixing syntax errors is left as an exercise for the reader
lookuptbl = 'whatever'
q = "[include_in_gis] = 'X' "

lookuptbl2 = 'whatever_else'
q2 = "[facil_id_in_gdbs] = '%s' " # or %d depending on the datatype of facil_id

rows = gp.SearchCursor(lookuptbl, q)
for row in iter(rows.next, None): # This is magic to converts a cursor to an iterator
&amp;nbsp;&amp;nbsp;&amp;nbsp; facil_id = row.GetValue('facil_id')
&amp;nbsp;&amp;nbsp;&amp;nbsp; print facil_id

&amp;nbsp;&amp;nbsp;&amp;nbsp; rows2 = gp.SearchCursor(lookuptbl2, q2 % facil_id)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row2 in iter(rows2.next, None): # More magic...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print facil_id + "--already exists"
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
row2 = None
rows2 = None
row = None
rows = None
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 04:31:02 GMT</pubDate>
    <dc:creator>NiklasNorrthon</dc:creator>
    <dc:date>2021-12-12T04:31:02Z</dc:date>
    <item>
      <title>Comparing values in an Access table with filenames of existing GDB's</title>
      <link>https://community.esri.com/t5/python-questions/comparing-values-in-an-access-table-with-filenames/m-p/676493#M52384</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to use a lookup table to compare a list of facilities that need geodatabases with the geodatabases that already exist in order to generate a list of geodatabases that need to be created. My script is stopping after the first record in the table and does not continue to search through any subsequent records. Here is what I have so far:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;

lookuptbl = r"P:\\USACE Mobile 0610-01 2010 63D RSC NR Contract\\03-Source Documents\\GIS\\SITE_ID_LOOKUP.mdb\\new_facility"
q = '[include_in_gis] = ' + "'" + "X" + "'"
#prnt q
#IF q is satisfied, the gdb that is currently being processed was found in lookup table;
#If q is NOT satisfied, the script will skip the gdb alltogether; nothing will be done


rows = gp.SearchCursor(lookuptbl, q)
row = rows.next()

while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; facil_id = row.GetValue("facil_id")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print facil_id
&amp;nbsp;&amp;nbsp;&amp;nbsp; lookuptbl2 = r"P:\\USACE Mobile 0610-01 2010 63D RSC NR Contract\\03-Source Documents\\GIS\\SITE_ID_LOOKUP.mdb\\gdbs"
&amp;nbsp;&amp;nbsp;&amp;nbsp; q2 = '[facil_id_in_gdbs] = ' + "'" + facil_id + "'"
&amp;nbsp;&amp;nbsp;&amp;nbsp; #prnt q
&amp;nbsp;&amp;nbsp;&amp;nbsp; #IF q is satisfied, the gdb that is currently being processed was found in lookup table;
&amp;nbsp;&amp;nbsp;&amp;nbsp; #If q is NOT satisfied, the script will skip the gdb alltogether; nothing will be done
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = gp.SearchCursor(lookuptbl2, q2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print facil_id + "--already exists"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next()
&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; row = rows.next()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am new to writing scripts so any help you could give me would be much appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Feb 2011 12:40:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/comparing-values-in-an-access-table-with-filenames/m-p/676493#M52384</guid>
      <dc:creator>RachelWilliams</dc:creator>
      <dc:date>2011-02-18T12:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing values in an Access table with filenames of existing GDB's</title>
      <link>https://community.esri.com/t5/python-questions/comparing-values-in-an-access-table-with-filenames/m-p/676494#M52385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Your second cursor overwrite and destroys the first one. Your loops should be for loops instead. Don't complicate the queries unnecearily. Take advantage of python's alternative quoting syntaxes. And use format strings.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
# Untested, fixing syntax errors is left as an exercise for the reader
lookuptbl = 'whatever'
q = "[include_in_gis] = 'X' "

lookuptbl2 = 'whatever_else'
q2 = "[facil_id_in_gdbs] = '%s' " # or %d depending on the datatype of facil_id

rows = gp.SearchCursor(lookuptbl, q)
for row in iter(rows.next, None): # This is magic to converts a cursor to an iterator
&amp;nbsp;&amp;nbsp;&amp;nbsp; facil_id = row.GetValue('facil_id')
&amp;nbsp;&amp;nbsp;&amp;nbsp; print facil_id

&amp;nbsp;&amp;nbsp;&amp;nbsp; rows2 = gp.SearchCursor(lookuptbl2, q2 % facil_id)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row2 in iter(rows2.next, None): # More magic...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print facil_id + "--already exists"
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
row2 = None
rows2 = None
row = None
rows = None
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:31:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/comparing-values-in-an-access-table-with-filenames/m-p/676494#M52385</guid>
      <dc:creator>NiklasNorrthon</dc:creator>
      <dc:date>2021-12-12T04:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing values in an Access table with filenames of existing GDB's</title>
      <link>https://community.esri.com/t5/python-questions/comparing-values-in-an-access-table-with-filenames/m-p/676495#M52386</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;also posted on&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://gis.stackexchange.com/questions/6286/using-python-lookup-table-to-compare-records-with-existing-geodatabases"&gt;http://gis.stackexchange.com/questions/6286/using-python-lookup-table-to-compare-records-with-existing-geodatabases&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Feb 2011 14:23:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/comparing-values-in-an-access-table-with-filenames/m-p/676495#M52386</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2011-02-18T14:23:28Z</dc:date>
    </item>
  </channel>
</rss>

