I am developing an ArcPy script in ArcGIS Desktop 10.7 and using a file geodatabase feature class. I have a field called facility_id. I have tried using this field as a string field or as an integer field but have been miserably unsuccessful at using this field as a value in the arcpy.da.SearchCursor function. For my latest attempt I generate the value in facility_id from an integer field called x.
x = 123456 facility_id = "'" + str(x) + "'" print facility_id gives '123456'
I would like to do this:
cursor = arcpy.da.SearchCursor(facility_fc, ("SHAPE@XY"), "ASUFAC = '$facility_id'")
(ASUFAC is a string field) When I execute this line of code, nothing is selected. If I execute the following line of code, one record is selected from the feature class, and is correct:
cursor = arcpy.da.SearchCursor(facility_fc, ("SHAPE@XY"), "ASUFAC = '123456'")
What is the correct syntax to use in order to have a value from the facility_id field be evaluated correctly in the where clause of the arcpy.da.SearchCursor function?
I've reviewed the thread "Using numeric variable in where clause of Arcpy SearchCursor" and adapted what was given there but it only generates an error: Invalid SQL statement was used