[GIS] insert cursor “Row contains a bad value”

arcpycursor

I'm having a problem copying data from a shapefile to a feature class using an insert cursor. Here is the part that is causing trouble:

newRows = arcpy.InsertCursor(Target)
sourceRows = arcpy.SearchCursor(Christiansburg)

for source in sourceRows:
    neue = newRows.newRow()
    neue.setValue(TName, source.getValue(CName))
    newRows.insertRow(neue)

It takes data from a field in the source row, and then copies it to the new row. The trouble is, when the source row has a forward slash in it, it fails when I try to do the insert, saying "The row contains a bad value.". If I edit the forward slash out of the source data, it works fine. If I replace the variable with a hardwired string that has a forward slash in it, it also works fine, so I am not 100% sure that it is the forward slash causing the problem. I have tried using the str function on the result of getValue, and it still doesn't work. The field being copied from is street names, and the row causing trouble is a street that changes name. If worst comes to worst, I could simply edit out the forward slash permanently, but I would rather not if I can help it.

Does anyone know what I am doing wrong here?

EDIT: Derped on copy/paste of code snippet. Should be fixed now.

Best Answer

I figured out what the problem was. Turns out, the field in the target feature class has a field length of 35 characters, while the corresponding field in the shapefile has a field length of 256 characters. The row that was causing problems was exactly 36 characters long, and was the only one that had a '/'. So when I deleted the '/' that brought the length to 35 characters and it worked. I suspect I spelled something wrong when I hardwired the string, so that is probably why that worked then. I truncated the row to 35 and it works like a charm, even with the '/'. So that must have been the problem. Thanks to all who took the time to reply and think about it, especially mapoholic. I noticed this testing his suggestion. I guess the moral of the story is to make sure that your fields are the right length when doing this sort of thing.

Related Question