English

FAQ: Why am I getting an error accessing a multivalue parameter in Python at ArcGIS for Desktop 10.1?

Question

Why am I getting an error accessing a multivalue parameter in Python at ArcGIS for Desktop 10.1?

Answer

The data type for a multivalue parameter in a Python script changed in ArcGIS for Desktop 10.1.

In ArcGIS Desktop 10.0, a multivalue parameter (a collection of items) was a ValueTable object. The following is an example of accessing a multivalue table name parameter in ArcGIS Desktop 10.0:

Code:
============
import arcpy

tableList = arcpy.GetParameter (0) # a ValueTable object
rowCt = tableList.rowCount
arcpy.AddMessage ("rows: " + str(rowCt))

i = 0
while i < rowCt:
# Get table name from list
tbl = tableList.getValue (i, 0)
arcpy.AddMessage ("table name: " + tbl)
i += 1
============


In ArcGIS for Desktop 10.1 and later, running the above code returns the following syntax error:
rowCt = tableList.rowCount
AttributeError: 'list' object has no attribute 'rowCount'


The error occurs because the multivalue parameter is now a list object. An example of the updated code is as follows:

Code:
============
import arcpy

tableList = arcpy.GetParameter (0) # a List object
rowCt = len (tableList)
arcpy.AddMessage ("rows: " + str(rowCt))

i = 0
while i < rowCt:
# Get table name from list
tbl = tableList[i]
arcpy.AddMessage ("table name: " + str(tbl))
i += 1
============