Invalid Expression Error

852
5
01-09-2013 08:46 AM
EmilyAgar1
New Contributor
I am trying to write a script that runs a select by location then a subset selection of select by attribute but I keep getting an invalid expression error. The last where clause is to selected any blank fields in the STD_CND field.

arcpy.SelectLayerByLocation_management("Culvert_subset", "INTERSECT", "Cont_Buff")
arcpy.SelectLayerByAttribute_management("Culvert_subset","SUBSET_SELECTION",'"STD_CND" = poor' or '"STD_CND = Very Poor' or '"STD_CND" = ""')

Additionally once this selection is made will it continue (or be saved) through the rest of the script or should I create a new shapefile from it?

Any thoughts?
Thanks!
Tags (2)
0 Kudos
5 Replies
MathewCoyle
Frequent Contributor
This is not a valid query.
'"STD_CND" = poor' or '"STD_CND = Very Poor' or '"STD_CND" = ""'

I'm not sure of your data schema but something like this might work.
'''"STD_CND" in ('poor', 'Very poor', '')'''
0 Kudos
EmilyAgar1
New Contributor
I tried those changes and got an invalid syntax error. STD_CND is a field within the Culvert_subset layer in which I am wanting to select all the culverts with a rating of poor, very poor or no rating
0 Kudos
MathewCoyle
Frequent Contributor
Post your exact code you executed and the error you received. Are you trying to do with through a script tool, python window, stand alone script?
0 Kudos
EmilyAgar1
New Contributor
I am just trying it in the python window right now, but it will be a piece to a tool that I am working on.
import arcpy
arcpy.env.workspace = "W:\ENG\Geomatics\PROJECT\Python Script"
 
arcpy.Buffer_analysis("5yrContract_subset", "Cont_Buff", "50 METERS", "FULL", "FLAT", "NONE")

arcpy.SelectLayerByLocation_management("Culvert_subset", "INTERSECT", "Cont_Buff")
arcpy.SelectLayerByAttribute_management("Culvert_subset","SUBSET_SELECTION", '''"STD_CND" in ('poor', 'Very Poor' '')'''
 
Parsing error <type 'exceptions.SyntaxError'>: invalid syntax (line 8)
0 Kudos
MathewCoyle
Frequent Contributor
You need a closing bracket and the last comma.

arcpy.SelectLayerByAttribute_management("Culvert_subset", "SUBSET_SELECTION", '''"STD_CND" in ('poor', 'Very Poor', '')''')
0 Kudos