checkvar = "cursor empty" rows = arcpy.SearchCursor(fc, query) for row in rows: if checkvar == "cursor empty": checkvar = "cursor full" print checkvar
row = None rows = arcpy.SearchCursor(fc, query) for row in rows: #cursor things if not row: print "cursor was empty"
arcpy.MakeFeatureLayer_management(indxTileFC, indxTileFL, "HCPUNIT_NM <> 'OESF'); showGpMessage() if int(arcpy.GetCount_management(indxTileFL).getoutput(0)) == 0: print "Query returned no records!" else: #if there are records returned by the query, then run a search cursor and look for Null field values in MY_FIELD searchRows = arcpy.SearchCursor(indxTileFC, "HCPUNIT_NM <> 'OESF') for searchRow in searchRows: if searchRow.MY_FIELD == None: #Another way: if searchRow.isNull("MY_FIELD") == True: print "MY _FIELD is Null!" del searchRow, searchRows
import arcgisscripting gp = arcgisscripting.create(9.3) table = 'C:/Users/lilaandmax/Downloads/AttributeCrosswalk.dbf' ####### the following three0FC works three0FC = 'AirfieldSurface' ######## but if you do this, three0FC = 'XAirfieldSurface' ## nothing happens query = "Three0FCla = '" + three0FC + "'" row, rows = None, None rows = gp.SearchCursor(table, query) for row in rows: if row.isNull("Three0FCla"): print "isNull" elif row == None: print "None" elif row == "": print "emptyspace" else: print row.getValue("Three0FCla")
for row in rows:
#STEP1: Execute a SQL query (the MakeFeatureLayer tools is probably the quickest way to do this) arcpy.MakeFeatureLayer_management(indxTileFC, indxTileFL, "HCPUNIT_NM <> 'OESF') #STEP2: Are any records returned? If 0 records satisfy the SQL query, then let us know! If 0 records are returned, the SQl query is probably incorrect!!! if int(arcpy.GetCount_management(indxTileFL).getoutput(0)) == 0: print "Query returned no records!" #STEP3: If there are records returned by the query, then run a search cursor and look for Null field values in MY_FIELD else: #Create a search cursor object using the same query as the one in the MakeFeatureLayer searchRows = arcpy.SearchCursor(indxTileFC, "HCPUNIT_NM <> 'OESF') #For each row in the collection of search cursor rows for searchRow in searchRows: #if the value in the "MY_FIELD" field is Null let us know... If theer are no Null values in the MY_FIELD field, then no message will be printed. if searchRow.MY_FIELD == None: #Another way: if searchRow.isNull("MY_FIELD") == True: print "MY _FIELD is Null!" #Delete the search cursor objects so the read lock is released on the search cursor table del searchRow, searchRows
If your cursor is empty, it will never step in. Nothing in the loopfor row in rows:
will execute because there is no row in rows, if you follow.
So I tested your code and came back with 4 rows, is that right? i am confused, I thought you wanted to test if the cursor object was empty?