ArcGIS 10.1 arcpy Update Cursor is returning a list instead of a row

I keep getting the following error:

Traceback (most recent call last): File "", line 16, in TitleLine = ""+row.getValue(IDfield)+" ("+ row.getValue(Datefield)+") "

AttributeError: 'list' object has no attribute 'getValue'

When I am trying to run a typical for row in cursor loop when working with an UpdateCursor. For the life of me, I can't figure out why it thinks the row is a list and not a row object. Here is my script:

import arcpy SourceTable = arcpy.GetParameterAsText(0) IDfield = arcpy.GetParameterAsText(1) Datefield =arcpy.GetParameterAsText(2) SelectedParams = arcpy.GetParameterAsText(3) OutputField = arcpy.GetParameterAsText(4) SelectedFields = SelectedParams.split(';') AllFields = arcpy.ListFields(SourceTable) FieldDict = {} for field in AllFields: FieldDict[]=field.aliasName with arcpy.da.UpdateCursor(SourceTable,"*") as cursor: for row in cursor: TitleLine = ""+row.getValue(IDfield)+" ("+ row.getValue(Datefield)+")" LabelList = [TitleLine] for Field in SelectedFields: if row.getvalue(Field) <>0: Alias = FieldDict.get(Field) ParamValue = row.getValue(Field) ParamLine = '{0} = {1:,}'.format(Alias,ParamValue) LabelList.append(ParamLine) if len(LabelList)<2: LabelList.append("All < 2L") Label = '
'.join(LabelList) row[OutputField] = Label cursor.updateRow(row) del row, cursor

Does anybody have any ideas where I'm screwing up on this?

You're using an arcpy.da.UpdateCursor. It by definition and design returns rows as lists, not as row objects. You need to use an arcpy.UpdateCursor if you want row objects.

The old arcpy objects from 10.0 likearcpy.*Cursorare still there in 10.1 and still behave as expected. You can even use the old 9.3arcgisscriptingAPIs and they'll still work the same. You don't need to "upgrade" your scripts to use the new APIs if they already work.

The line:

arcpy.da.UpdateCursor(SourceTable,"*") as cursor:

sees cursor.updateRow(row) as updating with a "tuple",

Try the following:



Watch the video: GIS Tutorial: ArcMap Custom Toolbars Tutorial (October 2021).