I have the following, i am trying to select and delete all the empty and null attributes but when i run the code the output feature class is empty. I am not sure what i am doing wrong, the SelectLayerByAttribute_management works in Arcmap python window.
# Process: Make Feature Layer
TAX1 = "in_memory\TaxPar"
arcpy.MakeFeatureLayer_management(Taxparcels, TAX1)
#Delets Parcels that are blank, NULL or start with Q
query = "DXF_TEXT LIKE 'Q%' or DXF_TEXT = ' ' or DXF_TEXT IS NULL"
arcpy.SelectLayerByAttribute_management(TAX1, "NEW_SELECTION", query)
if int(arcpy.GetCount_management(TAX1).getOutput(0)) > 0:
arcpy.DeleteFeatures_management(TAX1)
arcpy.FeatureClassToFeatureClass_conversion(TAX1, "D:/GIS Folder/Blah/blah.gdb", "Blah2")
Solved! Go to Solution.
You are over thinking it a bit, there is no reason in introduce a search cursor. The following will get the same results but is more straightforward and quicker:
mem_fc = arcpy.CopyFeatures_management(Taxparcels, r"in_memory\TaxPar")
fl = arcpy.MakeFeatureLayer_management(mem_fc, "TaxPar")
query = "DXF_TEXT LIKE 'Q%' or DXF_TEXT = ' ' or DXF_TEXT IS NULL"
arcpy.SelectLayerByAttribute_management(fl, "NEW_SELECTION", query)
if int(arcpy.GetCount_management(fl).getOutput(0)) > 0:
arcpy.DeleteFeatures_management(fl)