I have looked at Including variable in where clause of arcpy.Select_analysis()? and while it is very similar to the question I'm asking I ran into the same issue after implementing its syntax. I feel like I'm still missing something related to how to implement the correct syntax for the below.
where_query = '"field_name" <= ' "{0}.format(year_range)"
I'm trying to make what into a geoprocessing tool that can be reused in ArcMap, but I'm receiving the following error. It looks like an issue with the way that I'm formatting the where_query variable, but I can't seem to get it right.
Traceback (most recent call last):
File "C:\ArcPy\mean_center_drift.py", line 19, in <module>
arcpy.Select_analysis(in_feature, year_out_name, where_query)
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\analysis.py", line 84, in Select
raise e
ExecuteError: ERROR 000358: Invalid expression 1
Failed to execute (Select).
and here is the code in its current form.
import os
import arcpy
in_feature = arcpy.GetParameterAsText(0)
out_features = arcpy.GetParameterAsText(1)
origin_year = arcpy.GetParameterAsText(2)
field_name = arcpy.GetParameterAsText(3)
for x in range(10, 140, 10):
year_range = int(origin_year) + x
where_query = '"field_name" <= ' "{0}.format(year_range)"
year_out_name = os.path.join(out_features, "Years_{0}".format(x))
mean_out_name = os.path.join(out_features, "Mean_{0}".format(x))
arcpy.Select_analysis(in_feature, year_out_name, where_query)
arcpy.MeanCenter_stats(year_out_name, mean_out_name, "#", "#", "#")