ArcPy RuntimeError – How to Sum Fields from ListFields While Avoiding RuntimeError: A Column Was Specified That Does Not Exist

arcpycursor

Does anyone have a suggestion on how to otherwise solve the problem …
The need to automatically generate all the columns from the table, the calculation of the sum, the results are updated in the new column? Recognizing the conditions: 1) did not know the names of columns 2) the name of the column to update the known
example table:

enter image description here

PS
I am an absolute beginner in python programming

 import arcpy, os, string
 fc = "D:\\path\\test.shp"



 fieldNameList = []
 fields = arcpy.ListFields(fc, "*")

    for field in fields:
       if field.type in ("Double", "Integer", "Single", "SmallInteger"):

          fieldNameList.append(field.name)
          fn = "'" + "', '".join(fieldNameList) + "'"
 print(fn)   
 with arcpy.da.UpdateCursor(fc, [fn]) as cursor:

 for row in cursor:

            row[4] = row[0] + row[1] + row[2] + row[3]
            cursor.updateRow(row)

ERROR – RESULT

 >>> 
 'tt', 'ff', 'vv', 'rr', 'update'

 Traceback (most recent call last):
   File "E:\path\test.py", line 17, in <module>
   for row in cursor:
 RuntimeError: A column was specified that does not exist.
>>> 

Best Answer

edit: I didn't quite get what you were trying to do, but this should work as a sort of cumulative function.

Untested (there may be some errors with indices):

import arcpy, os, string

fc = "D:\\path\\exampless.shp"

fields = arcpy.ListFields(fc)

fieldNameList = []

for field in fields:
    if field.type in ("Double", "Integer", "Single", "SmallInteger"):
        fieldNameList.append(field.name)
        fn = ("'" + "', '".join(fieldNameList) + "'")

with arcpy.da.UpdateCursor(fc, fn) as cursor:
    for row in cursor:
        myValue = 0
        for i in range(len(fn)):    
            myValue = myValue + row[i]
        row[len(fn)] = myValue
        cursor.updateRow(row)