Hello all - 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. Thank you 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
<module>
cursor.updateRow(row) TypeError: value #0 - unsupported type: tuple
Failed to execute (SumFieldInsertNew).
Solved! Go to Solution.
It looks like you are missing a right parentheses on your "b" variable.
#Current b variable b = sum(row[0] for row in arcpy.da.SearchCursor(fc, 'QUANTITY_SOLID')),DefQ #This returns both the b variable and the definition query separated by a comma similar to a tuple #Should be to return a value of b from a search cursor with definition query DefQ b = sum(row[0] for row in arcpy.da.SearchCursor(fc, 'QUANTITY_SOLID',DefQ))
The original script has the definition query outside the parameters of the SearchCursor tool. Then when the "b" variable is called later on, it is read as a tuple instead of a single string/integer/float/etc. By moving the definition query inside the parentheses, it should return a value "b" from search cursor with definition query "DefQ". This should return a single variable instead of a tuple.
It looks like you are missing a right parentheses on your "b" variable.
#Current b variable b = sum(row[0] for row in arcpy.da.SearchCursor(fc, 'QUANTITY_SOLID')),DefQ #This returns both the b variable and the definition query separated by a comma similar to a tuple #Should be to return a value of b from a search cursor with definition query DefQ b = sum(row[0] for row in arcpy.da.SearchCursor(fc, 'QUANTITY_SOLID',DefQ))
The original script has the definition query outside the parameters of the SearchCursor tool. Then when the "b" variable is called later on, it is read as a tuple instead of a single string/integer/float/etc. By moving the definition query inside the parentheses, it should return a value "b" from search cursor with definition query "DefQ". This should return a single variable instead of a tuple.
Here is a picture showing the output when DefQ is outside the parameters.
Great, thank you very much for breaking it down for me so I could understand exactly what was happening. I appreciate the help!
Looks like the your issue is at line 18.
b = sum(row[0] for row in arcpy.da.SearchCursor(fc, 'QUANTITY_SOLID')),DefQ
This should be
b = sum(row[0] for row in arcpy.da.SearchCursor(fc, 'QUANTITY_SOLID',DefQ))
Thank you for your help Riyas!