I keep getting the following error:
Traceback (most recent call last):
File "R:\GIS_ScriptsandTools\PullHotParametersLabel.py", line 16, inTitleLine = ""+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.name]=field.aliasName
with arcpy.da.UpdateCursor(SourceTable,"*") as cursor:
for row in cursor:
TitleLine = "<und><bol>"+row.getValue(IDfield)+" </bol>("+ row.getValue(Datefield)+")</und>"
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 = '\n'.join(LabelList)
row[OutputField] = Label
cursor.updateRow(row)
del row, cursor
Does anybody have any ideas where I'm screwing up on this?
Best Answer
You're using an
arcpy.da.UpdateCursor
. It by definition and design returns rows as lists, not as row objects. You need to use anarcpy.UpdateCursor
if you want row objects.The old arcpy objects from 10.0 like
arcpy.*Cursor
are still there in 10.1 and still behave as expected. You can even use the old 9.3arcgisscripting
APIs and they'll still work the same. You don't need to "upgrade" your scripts to use the new APIs if they already work.