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

    bufferDistance = creekWidth*0.5
    if crossingType == "INTERSECT":
        stringBuffer = ""
        stringBuffer = "%s Meters" % 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.CalculateField_management(targetLayer, outputField2, int(score) )

            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).

  • 3
    Please tell us what the problem is: how does the system respond? – whuber Sep 29 '14 at 19:31
  • Try classname = '"Virtual Flow"' – Erica Sep 29 '14 at 19:49
  • sorry and I thought something was missing. – Solaire Sep 30 '14 at 13:42
  • I tried putting the variable classname in between ' 'as in arcpy.CalculateField_management(targetLayer, outputField1, 'classname') but it didnt work. @Erica – Solaire Sep 30 '14 at 13:44
  • No, the single-quotes should be around the string where you define the variable classname, not around the variable name in the arcpy function. (I'm not sure that will work, mind you, it's just an idea.) – Erica Sep 30 '14 at 13:52

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.
| improve this answer | |
  • arcpy.AddField_management(inFeatures, nameField,"TEXT") arcpy.CalculateField_management(inFeatures, nameField, '"No Creek"') – Solaire Sep 30 '14 at 16:37
  • these are the lines that create ROW_1, then gives it an intial value of "No Creek". the value from the tuple is supposed to overwrite "No Creek" – Solaire Sep 30 '14 at 16:39

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

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


| improve this answer | |
  • I have already tried that and its not working :( – Solaire Sep 30 '14 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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