Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python arcpy计算字符串字段:有什么办法解决这个问题吗?_Python_Arcpy_Calculated Field - Fatal编程技术网

Python arcpy计算字符串字段:有什么办法解决这个问题吗?

Python arcpy计算字符串字段:有什么办法解决这个问题吗?,python,arcpy,calculated-field,Python,Arcpy,Calculated Field,我试图将通过元组从循环中获得的字符串值存储到名为ROW_1的字段中 代码是这样的 for creekclass in listOfClassTuples: (classname, Permanency, creekWidth, score) = creekclass arcpy.AddMessage(int(score)) bufferDistance = creekWidth*0.5

我试图将通过元组从循环中获得的字符串值存储到名为ROW_1的字段中

代码是这样的

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

    except:

        arcpy.AddMessage("Function failed")
        arcpy.AddMessage(arcpy.GetMessages())
当变量classname等于“Virtual Flow”时出现问题:

classname=“虚拟流”

下一行取自上述代码

if outputField1 != "":                                        

                            arcpy.CalculateField_management(targetLayer, outputField1, classname)

根据esri帮助中的语法:

CalculateField_management (in_table, field, expression, {expression_type}, {code_block})
第三个参数是SQL表达式。由于传递的字符串中可能有空格,因此表达式需要用单引号“”括起来

像这样的方法应该会奏效:

if outputField1 != "":                                        

                        arcpy.CalculateField_management(targetLayer, outputField1, "".join(("'",classname,"'"))