Python脚本给出'TypeError - Unsupported Type:Tuple'

时间:2014-08-13 13:01:38

标签: python python-2.7 typeerror arcgis

我对Python很陌生,所以我想知道是否有人可以告诉我为什么我的脚本会返回以下错误。是的,我已经查明了错误及其含义,但对于导致错误的原因我有点不清楚。提前谢谢!

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)

我收到以下错误:

  

Traceback(最近一次调用最后一次):文件“example.py”,第23行,in          cursor.updateRow(row)TypeError:value#0 - 不支持的类型:tuple

     

执行失败(SumFieldInsertNew)。

1 个答案:

答案 0 :(得分:0)

我不知道arcpy api而是行

b = sum(row[0] for row in arcpy.da.SearchCursor(fc, 'QUANTITY_SOLID')),DefQ

将b设置为元组。当你执行row[0] = b然后将其传递给updateRow时,我想它并不期待一个元组。