The first thing I would recommend is using more parameters in the search cursor to increase performance.I would start by hardcoding the values in a very simplistic cursor, once you have that working, I would try to build in the remainder of the logic.{Example}SearchCursor (dataset, {where_clause}, {spatial_reference}, {fields}, {sort_fields})I noticed in your code you are building a query string and also search on a particular field.To increase performance, I would not recommend doing a full table scan each time and searching for a field in a loop. I would limit the fields in the cursor itself which should prevent full table scans, also by specifying the where_clause in the cursor itself you should notice a performance gainI would try something like this to start;fieldName = "Name" rows = arcpy.SearchCursor("yourlayername","where_clause="build your query here", "",fieldName,"A") for row in rows: print row.getValue(fieldName)
Esri's now recommends doing it this way at 10.1. Notice the {0} corresponds to fieldName and {1} to gisNum. This allows more flexibility in formatting strings rather than mixing double and single quotes with plus signs. A little cleaner as well.query = "Name = " + "'" + "g" + gisNum + ".tif" + "'"fieldName = "Name" querystring = " UPPER(\"{0}\") = UPPER('g{1}.tif') ".format(fieldName,gisNum)) rows = arcpy.SearchCursor("yourlayername","where_clause=querystring, "",fieldName,"A") for row in rows: print row.getValue(fieldName)
If you are at 10.1 look into arcpy.da.SearchCursor, it will outperform the 10.0 SearchCursor. At 10.0 there were performance issues with the SearchCursor especially when you have Subtypes or Domains in your data and if your data was in SDE.