I have been working on a code to automate the process of finding the relative probability of failure for all of the water mains in a city and am having a problem using select by attributes. The code gives me an error saying "invalid expression". I have narrowed it down to this line:
Select(AC_Fail,"NEW_SELECTION",ACFDia + ' = ' + str(x))
I know this is the line giving me problems because I commented it out and the rest of the script ran fine. The line before is written the exact same way, but it works. (Weird)Below, I have included everything in my script just to past the point where I am getting the error.
import arcpy, sys
arcpy.env.workspace = "C:\Data\ArcGIS\Default.gdb"
#Define input and output variables
WaterPipes = sys.argv[1]
WPID = sys.argv[2]
WDia = sys.argv[3]
YearInst = sys.argv[4]
AC_Fail = sys.argv[5]
ACFDia = sys.argv[6]
SoftPunky = sys.argv[7]
PipeTests = sys.argv[8]
FailCategory = sys.argv[9]
ServiceFail = sys.argv[10]
OEM = sys.argv[11]
Probability = sys.argv[12]
#Define variables to make code readable
Select = arcpy.SelectLayerByAttribute_management
SpatialJoin = arcpy.SpatialJoin_analysis
Merge = arcpy.Merge_management
AddField = arcpy.AddField_management
MakeLayer = arcpy.MakeFeatureLayer_management
Calculate = arcpy.CalculateField_management
JoinField = arcpy.JoinField_management
Delete = arcpy.Delete_management
#Clear any selections on all input layers
Select(WaterPipes, "CLEAR_SELECTION")
Select(AC_Fail, "CLEAR_SELECTION")
Select(SoftPunky, "CLEAR_SELECTION")
Select(PipeTests, "CLEAR_SELECTION")
Select(ServiceFail, "CLEAR_SELECTION")
#Define pipe sizes
dia = []
rows = arcpy.SearchCursor(WaterPipes,"","",WDia,"")
for row in rows:
if getattr(row, WDia) not in dia:
dia.append(int(getattr(row, WDia)))
#For each pipe size, select all pipes of that size on the water pipes layer and the AC failure layer
#Join the two layers together to create a layer that counts the number of
#failures on the same diameter of pipe within 100 feet.
layers = []
for x in dia:
Select(WaterPipes,"NEW_SELECTION",WDia + ' = ' + str(x))
Select(AC_Fail,"NEW_SELECTION",ACFDia + ' = ' + str(x))
SpatialJoin(WaterPipes,AC_Fail,'Fail100' + str(x),"JOIN_ONE_TO_ONE","KEEP_ALL","","INTERSECT",100,"Dist")
layers.append('Fail100' + str(x))
#Merge all of the different pipe size layers together into one layer.
Merge(layers,"Fail100ft")
Why isn't this working?Any help is much appreciated. If I haven't included enough information, let me know. Thanks,Matt