Skip to main content
edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
added 46 characters in body
Source Link
GeoF
  • 391
  • 2
  • 8

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, triedfails with ExecuteError: ERROR 000358: Invalid expression. Tried different things but not working!

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!

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 fails with ExecuteError: ERROR 000358: Invalid expression. Tried different things but not working!

Source Link
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!