Select to view content in your preferred language

Select Layer by attributes PYthon scripting through files

1898
1
05-16-2013 09:30 AM
SamHuang
New Contributor II
Hi guys,

Just a quick question as i've been having trouble with my python script that I"ve been trying to implement. The issue here is that everytime when I try to run my script, I keep getting the following error

ERROR 000358: Invalid expression
Failed to execute (SelectLayerByAttribute).


I believe there's an issue with the following section with its expression, but i'm not very clear how i can fix this. Anythoughts on this would be greatly appreciated!

#select layer by attributes
            arcpy.MakeFeatureLayer_management(unionwtrshd, 'unionwtrshdlyr')
            exp2 = " \"FIDPAO_" + str(ws_id) + "\" = -1"
            arcpy.SelectLayerByAttribute_management('unionwtrshdlyr', "NEW_SELECTION", exp2)

and fyi, str(wd_id) is already defined.

Essentially i'm trying to run a script where it goes through each files and grab their respective field 'FIDPAO_(wd_id)"


Thanks!
Tags (2)
0 Kudos
1 Reply
by Anonymous User
Not applicable
You can actually make the feature layer with that selection applied (where clause is optional parameter).

Try this:
exp2 = '"FIDPAO_%s" = -1' %ws_id
arcpy.MakeFeatureLayer_management(unionwtrshd, 'unionwtrshdlyr', exp2)
0 Kudos