AnsweredAssumed Answered

Invalid Expression Error in Loop

Question asked by jplay on Apr 21, 2014
Latest reply on Apr 21, 2014 by jplay
I'm extremely confused. I set up a loop to select features by attribute from a list of feature classes. The script runs completely through the list doing exactly what it's supposed to do. But then I receive and invalid expression error.

Messages:
Selecting by COFIPS
Selecting S_POL_AR
Selecting S_COMMUNITY_GROUP
Selecting V_P_FLD_HAZ_AR
Selecting V_P_FLD_HAZ_LN
Selecting V_P_HYDRAMODEL
Failed script FRISGeodatabasev12...
Traceback (most recent call last):
File "\\Ncemjfhqfs01\gtm\GIS\GTM_GIS_Tools\Scripts\FRISGeodatabase_v1.2.py", line 260, in <module>
arcpy.SelectLayerByAttribute_management (featurelayer, "NEW_SELECTION", CLAUSE)
File "c:\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).

The cod is as follows:
PrelimSelectByCOFIPS = ["Database Connections\NC_FLOOD.sde\NC_FLOOD.DBO.BASE\NC_FLOOD.DBO.S_POL_AR", "Database Connections\NC_FLOOD.sde\NC_FLOOD.DBO.BASE\NC_FLOOD.DBO.S_COMMUNITY_GROUP", "Database Connections\NC_FLOOD.sde\NC_FLOOD.DBO.FLOOD\NC_FLOOD.DBO.V_P_FLD_HAZ_AR", "Database Connections\NC_FLOOD.sde\NC_FLOOD.DBO.FLOOD\NC_FLOOD.DBO.V_P_FLD_HAZ_LN", "Database Connections\NC_FLOOD.sde\NC_FLOOD.DBO.FLOOD\NC_FLOOD.DBO.V_P_HYDRAMODEL"]

# Select Features by COFIPS
arcpy.AddMessage("Selecting by COFIPS")
CLAUSE = ('{0} = {1}'.format ("CO_FIPS", COFIPS))
for feature in PrelimSelectByCOFIPS:
    outfeaturename = string.join(feature.rstrip().split('.')[-1:],'.')
    arcpy.AddMessage("Selecting " + outfeaturename)
    featurelayer = os.path.join(FRIS_FGDB, outfeaturename + "_layer")
    COFIPSfeature = os.path.join(FRIS_FGDB, outfeaturename)
    arcpy.MakeFeatureLayer_management(feature, featurelayer)
    arcpy.SelectLayerByAttribute_management (featurelayer, "NEW_SELECTION", CLAUSE)
    arcpy.CopyFeatures_management(featurelayer, COFIPSfeature)
    arcpy.Delete_management(featurelayer)


I have the exact same loop set up two other times before this in the script to select by location and to clip by selected feature and neither of those give me any issue.

What is going on here?

Outcomes