I'm working with ArcGIS 10.2. I used this code to select one record of an attribute table:
import arcpy
# Set the workspace
env.workspace = "F:ArcGIS\Trab\Model\Lin_150_tr.shp"
# Make a layer from the feature class
arcpy.MakeFeatureLayer_management("Lin_150_tr", "lyr5")
arcpy.SelectLayerByAttribute_management("lyr5", "NEW_SELECTION", ' "FID" = 2 ')
And it works! Now I need to select no one record but some records of the same table, so I used a list of values and a loop:
import arcpy
env.workspace = "F:ArcGIS\Trab\Model\Lin_150_tr.shp"
arcpy.MakeFeatureLayer_management("Lin_150_tr", "lyr5")
crit_150=[2,10,200,323,349,384,433]
for a in crit_150:
arcpy.SelectLayerByAttribute_management("lyr5", "NEW_SELECTION", ' "FID" = a ')
But it gives me an error:
Runtime error Traceback (most recent call last): File "<string>", line 21, in <module> File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6494, in SelectLayerByAttribute raise e ExecuteError: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute).
How can I do this?