Skip to main content
1 of 3
GeoF
  • 391
  • 2
  • 8

Select Layer by Attribute clause fails

I have a shapefile and I want to loop through every column and extract selected features with the specified criteria (Column has a P or L).

So my code is like

output = "All.shp"

fields = arcpy.ListFields(output)

for field in fields:
    arcpy.MakeFeatureLayer_management("all.shp", "lyr")
    name = field.name

    clause = name + " LIKE 'P' OR "+ name + " LIKE 'L'"


    arcpy.SelectLayerByAttribute_management("lyr", "NEW_SELECTION", clause)

    arcpy.CopyFeatures_management("lyr", field.name+".shp")

Clause seems to fail, tried different things but not working!

GeoF
  • 391
  • 2
  • 8