I've come across this problem a few times and have not been able to find a satisfactory answer. I am new to Python though so perhaps I have not been looking in the right places!
Anyway, In ArcGIS I have been using the following code to select entries by attribute in the attribute table:
import arcpy arcpy.env.workspace = "C:\Users\T0015685\Documents\WCGIS\Geog485\Lesson1\us_hydro.shp" qry = '"COUNTRY" = \'CANADA\'' flayer = arcpy.MakeFeatureLayer_management("us_hydro", "us_hydro_Hudson6") arcpy.SelectLayerByAttribute_management(flayer, "NEW_SELECTION", qry) cnt = arcpy.GetCount_management(flayer) print "The number of selected records is: " + str(cnt)
This script works fine. HOWEVER, when I alter the query entries from verbal to numeric attributes I get an error. So, for example, if I change the query to - qry = '"HYDRO_= \'1744\'' - the script fails. I think this is something to do with the SQL expression but I'm not sure.
I want to be able to use code such as this to search feature ID's but can't because every time I use numbers the code doesn't work. Could someone please explain why this is the case or perhaps offer a solution.