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
Solved! Go to Solution.
Hi Ahsan,
You will just need to change the line:
cursor.updateRow([row])
to:
cursor.updateRow(row)
and your code should work.
Hi Ahsan,
You will just need to change the line:
cursor.updateRow([row])
to:
cursor.updateRow(row)
and your code should work.
Thank you Jake, i was so much confused, but you solved my problem.