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

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.

  • Do you have nulls? What version of ArcGIS are you on? Commented Aug 7, 2012 at 20:35
  • There are nulls in other fields, however, there are none in field that is causing trouble, either in the feature class or shapefile. Have 10.0
    – fomafomich
    Commented Aug 7, 2012 at 20:40
  • ahmm shouldnt you use: newRows.insertRow(neue) after you are finished iterating sourceRows? setValue() is filling just one field in a row or multiple fields simultaneously?
    – Gero
    Commented Aug 7, 2012 at 20:53
  • As I understand it, it needs to be done for each row. setValue fills a single field in a single row. So you create a row object, fill it with setValue as needed, insert the row into the table, and move on to next source row, hence the loop. I am actually using other setValue statements for other fields in my full code, but only what I have posted is causing problems. Even that is not consistently problematic, since it only seems to cause problems when the source row has a '/' in it, and I can't figure out how to fix it.
    – fomafomich
    Commented Aug 7, 2012 at 22:36
  • Maybe arcpy think the street name is a filepath. Why don't you try to add a backslash () in the value so it sees it as a 'raw' string e.g. from 'old name/new name' to old name\/new name'. Worths a try...
    – mapoholic
    Commented Aug 8, 2012 at 7:07

2 Answers 2


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.

  • I had a similar issue, but for me it had to do with a mismatch of number type fields - I was trying to calculate a long integer into a short integer field and the number was too large for the short integer field.
    – mTy
    Commented Mar 11, 2022 at 23:59

I had this issue with Append Tool. I started an Edit Session and the errors went away! weird!

  • This comment solved the problem for me. I have been pulling my hair out over this for the last 3 days. Commented Oct 10, 2016 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.