Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am trying to use python to look through an access table containing facilities that need to have geodatabases with geodatabases that already exist in order to generate a list of facility geodatabases that still need to be created. The script is working but the loop is stopping at the first record of the table and not continuing to page through the rest of the records. Here is what I have:

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" + "'"


rows = gp.SearchCursor(lookuptbl, q)
row = rows.next()

while row:
    facil_id = row.GetValue("facil_id")
    lookuptbl2 = r"P:\\USACE Mobile 0610-01 2010 63D RSC NR Contract\\03-Source     Documents\\GIS\\SITE_ID_LOOKUP.mdb\\gdbs"
    q2 = '[facil_id_in_gdbs] = ' + "'" + facil_id + "'"
    #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(lookuptbl2, q2)
    row = rows.next()

    while row:
        print facil_id + "--already exists"
        row = rows.next()


    row = rows.next()        

I'm new to scripts so any help would be appreciated. Thanks!

share|improve this question
add comment

1 Answer

It may be because you reset the searchcursor in the first while loop.

import arcpy
a_file = "c:/temp/x.shp"
desc = arcpy.Describe
rows = arcpy.SearchCursor(a_file)
row = rows.next()
some_field = desc(a_file).OIDFieldName

another_file = "c:/temp/x1.shp"
some_field2 = desc(another_file).OIDFieldName

msg = ""
while row:
  msg += "\nrow : " + str(row.getValue(some_field)) + "\n  row2"
  #
  rows2 = arcpy.SearchCursor(a_file)
  row2 = rows.next()
  while row2:
    msg += " " + str(row2.getValue(some_field2))
    row2 = rows2.next()
  row = rows.next()
print msg

In the above example two shapefiles were queried on the FID field, here are the results

row : 0 row2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

.....snip

row : 14 row2 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

representing the nested queries. If the rows2 and row2 elements are changed to rows and row, then the output is

row : 0 row2 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

which is not what you want, I am assuming

share|improve this answer
    
another example of the continuing double-posting between this site and the esri site forums.arcgis.com/threads/… –  Dan Patterson Feb 18 '11 at 16:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.