AnsweredAssumed Answered

Problem in Inserting Row in shape file using Python,

Question asked by ahsan_phy@hotmail.com on Dec 9, 2014
Latest reply on Dec 10, 2014 by ahsan_phy@hotmail.com

Complete problem to solve ?

Write a script that adds a text field to the roads.shp feature class called FERRY and populates this field with YES and NO values, depending on the value of the FEATURE field.

Below is my code, but i got an error (" sequence size must match size of the row "), Please help me...

 

fc = "roads.shp"

newfield = "FERRY"

fieldtype = "TEXT"

fieldname = arcpy.ValidateFieldName(newfield)

fieldlist = arcpy.ListFields(fc)

 

 

if fieldname not in fieldlist:

    arcpy.AddField_management(fc, fieldname, fieldtype, "", "", 12)

    print "New field has been added."

else:

    print "Field name already exists."

 

 

cursor = arcpy.da.UpdateCursor(fc, ["FEATURE","FERRY"])

 

 

for row in cursor:

    if row[0] == "Ferry Crossing":

        #print row[0]

        #cursor.insertRow("YES")

        row[1] = "YES"

    else:

        #print row[0]

        #row.insertRow("NO")

        row[1] = "NO"

    cursor.updateRow([row])

del row

del cursor

Outcomes