I'm currently trying to iterate through the features of a feature class (using an update cursor, because the goal is to ultimately update the field) and buffer each individual segment. I eventually want to use the buffer in each iteration with different tools, but I can't get the initial Select by Attribute to work. Here's my code:
fc = "Original_Clip"
fcfield = "SEGMENTID"
strt_lyr = arcpy.MakeFeatureLayer_management(fc, "Street_lyr")
with arcpy.da.UpdateCursor(fc, fcfield) as cursor:
for row in cursor:
var_segment = row[0]
print "Buffering segment " + str(var_segment)
arcpy.SelectLayerByAttribute_management(strt_lyr, "NEW_SELECTION", '{} = \'{}\''.format(var_segment))
arcpy.Buffer_analysis(strt_lyr, str(var_segment) + "Buff", "20 Feet")
When I run this code, an error is thrown with the SelectLayerByAttributefunction, saying my where clause is invalid?
Runtime error Traceback (most recent call last): File "", line 15, in File "d:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6688, in SelectLayerByAttribute raise e ExecuteError: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute). I'm assuming I just have the SQL syntax wrong (I'm querying a file geodatabase btw), but maybe what I'm trying to do just isn't possible.