I'm pretty new to Python so I was wondering if anyone could please tell me why my script is returning the following error. Yes, I have looked up the error and its meaning, but am a little unclear on what could be causing it. Thanks in advance!
import arcpy
# Define the feature class
fc = r'C:\path\to\your\fc'
# find the unique 'SEGMENT_LENGTH' values
Slist = list()
for row in arcpy.da.SearchCursor(fc, 'SEGMENT_LENGTH'):
# if the value isn't in the list then add it to the list
if not row[0] in Slist:
Slist.append(row[0])
for Value in Slist:
# definition query to limit the rows in the cursor
DefQ = 'SEGMENT_LENGTH = ' + str(Value)
# Use a generator expression to populate a list from the 'QUANTITY_SOLID' field
b = sum(row[0] for row in arcpy.da.SearchCursor(fc, 'QUANTITY_SOLID')),DefQ
with arcpy.da.UpdateCursor(fc, ['QUANTITY_SOLID_SUM'],DefQ) as cursor:
for row in cursor:
row[0] = b
cursor.updateRow(row)
I receive the following error:
Traceback (most recent call last): File "example.py", line 23, in cursor.updateRow(row) TypeError: value #0 - unsupported type: tuple
Failed to execute (SumFieldInsertNew).
I don't know the arcpy api but the line
b = sum(row[0] for row in arcpy.da.SearchCursor(fc, 'QUANTITY_SOLID')),DefQ
is setting b to a tuple. When you do row[0] = b
and then pass it to updateRow
I imagine it is not expecting a tuple.