Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

arcpy calculate string field: Any ideas what how to fix this?

$
0
0

I’m trying to store a string value obtained from a loop through a tuple into a field called ROW_1. The code goes like this:

for creekclass in listOfClassTuples:

    (classname, Permanency, creekWidth, score) = creekclass
    arcpy.AddMessage(int(score))

    bufferDistance = creekWidth*0.5
    if crossingType == "INTERSECT":
        stringBuffer = ""
    else: 
        stringBuffer = "%s Meters" % str(bufferDistance)
        arcpy.AddMessage(str(bufferDistance))
        arcpy.MakeFeatureLayer_management(sourceLayer, "JUST_SELECTED", fieldName +" = '"+ classname + "'")
        #arcpy.SelectLayerByAttribute_management("JUST_SELECTED", "NEW_SELECTION", fieldName+" = '"+ classname + "'")
        #arcpy.SelectLayerByAttribute_management("JUST_SELECTED", "SUBSET_SELECTION", fieldName2+" = '"+ Permanency + "'")
        #arcpy.CopyFeatures_management("JUST_SELECTED", "A:TemporaryTempLayer1.shp")                           
        arcpy.SelectLayerByLocation_management(targetLayer, crossingType, "JUST_SELECTED", stringBuffer, "NEW_SELECTION")
        ## classname = classname.lower()

        if outputField1 != "":                                        
            arcpy.CalculateField_management(targetLayer, outputField1, classname)
            #arcpy.AddMessage(str(classname))
            #arcpy.AddMessage(str(outputField1))

            arcpy.CalculateField_management(targetLayer, outputField2, int(score) )

            arcpy.Delete_management("Just_selected")
            arcpy.SelectLayerByAttribute_management(targetLayer, "CLEAR_SELECTION")

The problem appears in the following line taken from the code above

if outputField1 != "":                                        
    arcpy.CalculateField_management(targetLayer, outputField1, classname)

when the variable classname is equal to “Virtual Flow”:

classname = "Virtual Flow"

I get the following error:

Executing: CalculateField Big_Pipes ROW_1 “virtual flow” VB #
Start Time: Tue Sep 30 09:40:09 2014
General error executing calculator.
ERROR 999999: Error executing function.
Expected end of statement
Failed to execute (CalculateField).


Viewing all articles
Browse latest Browse all 767

Trending Articles