-1

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

  • 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
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.
  • 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
0

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

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

Documentation

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