I am trying to iterate through a field (integer values 1, 2, 3), select by each unique attribute, and run a tool on that selection of points.
My list is:
NearValues <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
And my for loop is the following (again, I want to select all of the points with a value of 1, run the median center tool on all of those points, then select all of the 2's, etc):
<SPAN class="keyword token">for</SPAN> value <SPAN class="keyword token">in</SPAN> NearValues<SPAN class="punctuation token">:</SPAN>
query <SPAN class="operator token">=</SPAN> <SPAN class="string token">"['nearstr']="</SPAN><SPAN class="operator token">+</SPAN>str<SPAN class="punctuation token">(</SPAN>value<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN>points<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NEW_SELECTION"</SPAN><SPAN class="punctuation token">,</SPAN> query<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MedianCenter_stats<SPAN class="punctuation token">(</SPAN>points<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"mediancenter_test"</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>value<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>It's giving me an Invalid expression error, so I'm not sure if it's a minor syntax thing or if there's something wrong with my methodology. Here is the complete error if it's helpful:
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 7605, in SelectLayerByAttribute
raise e
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 7602, in SelectLayerByAttribute
retval = convertArcObjectToPythonObject(gp.SelectLayerByAttribute_management(*gp_fixargs((in_layer_or_view, selection_type, where_clause, invert_where_clause), True)))
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 498, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 000358: Invalid expression
Failed to execute (SelectLayerByAttribute).
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>