Select to view content in your preferred language

Problem in Inserting Row in shape file using Python,

4581
2
Jump to solution
12-09-2014 11:44 PM
AhsanAbbas
Deactivated User

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

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi Ahsan,

You will just need to change the line:

cursor.updateRow([row])

to:

cursor.updateRow(row)

and your code should work.

View solution in original post

2 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Ahsan,

You will just need to change the line:

cursor.updateRow([row])

to:

cursor.updateRow(row)

and your code should work.

AhsanAbbas
Deactivated User

Thank you Jake, i was so much confused,  but you solved my problem.

0 Kudos