AnsweredAssumed Answered

Sequence Size error in Update Cursor

Question asked by jborgion Champion on Feb 27, 2019
Latest reply on Feb 28, 2019 by jborgion

I have this reoccurring nightmare... (see 'ascii' codec can't encode character u'\u201c'  )  I keep coming back to this script where I need to replace a new line ('\n') in a field.  I have somehow gotten past the error in the referenced thread, but now I'm faced with 

 

TypeError: sequence size must match size of the row

 

 

import arcpy
arcpy.env.workspace = r'J:\WaterQuality\test_tables.gdb'

table = 'FieldParameters'
fieldNames = [f.name for f in arcpy.ListFields(table,'','String')]
for fieldName in fieldNames:
   field = [fieldName]
    with arcpy.da.UpdateCursor(table,field) as cursor:
      for row in cursor:
        if row[0] == None:
          pass
        elif '\n' in row[0]:
          print(row[0])
          row[0] = row[0].replace('\n','=>')
          print(row[0])
          cursor.updateRow(row[0])
           
Water has a green/grey tint


Water has a green/grey tint=>=>

Line 18 through line 20 are returned from the print statement on line 13.  The actual value of the field is:

 

Water has a gren/grey tint\n\n

 

Line 21 is returned from the print statement on line 15: I have successfully replaced both \n characters with =>

 

However, it errors with:

 

Runtime error
Traceback (most recent call last):
File "<string>", line 23, in <module>  (line 23 is shown as line 16 above)
TypeError: sequence size must match size of the row

 

This table has 11 string fields, the first 9 do not have any \n characters in any of them.  I hit the 10th field and the first record it finds with a \n tosses the error.  

 

This is being run in the Arcpy window of ArcMap 10.6.1. I've tossed this error before with an insert cursor (see: Brain cramp with an Insert Cursor from 9 months ago) and I was able to resolve it then.  I just don't see what I'm doing wrong this time.

 

My goal is to loop through a list of tables and their respective string fields looking for \n characters and replace them accordingly.  In a  search cursor and find all the offenders just fine, but fixing them is another story.

Outcomes