AnsweredAssumed Answered

arcpy - Sum fields from ListFields - RuntimeError: A column was specified that does not exist?

Question asked by dbajic on Mar 6, 2015
Latest reply on Mar 6, 2015 by dbajic

Does someone can help?

 

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

 

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?

 

thanks in advance

 

PS I am an absolute beginner in python programming

Outcomes