-2

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:\Temporary\TempLayer1.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).

1
  • Here you have presented what appears to be a copy/paste from your code rather than a code snippet that can be copy/pasted into Python IDE ready to test. WHat is listOfClasses set to when your code starts?
    – PolyGeo
    Jun 20, 2022 at 20:10

2 Answers 2

1

when the variable classname is equal to "Virtual Flow":

 classname =  "Virtual Flow"

A couple of things to check if it works when classname is equal to other values:

  • Check the outputfield1 field type. If it's date or number field, you'll get an error since you're trying to set it to a string
  • If outputfield1 is a string field type, check it's length. If it's shorter than 12 characters, you'll get an error. If this is the case, either change the length of the field, or change it to this to truncate it.
0
0

The default expression type for CalculateField is VB. You need to specify Python:

arcpy.CalculateField_management(targetLayer, outputField1, classname, "PYTHON_9.3")

Documentation

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.