FAQ: Why am I getting an error accessing a multivalue parameter in Python at ArcGIS for Desktop 10.1?
【相关信息】
Article ID: 42668
Software:
ArcGIS for Desktop Advanced 10.1, 10.2
ArcGIS for Desktop Standard 10.1, 10.2
ArcGIS for Desktop Basic 10.1, 10.2
Platforms:
Windows XP, Vista, Windows 7, Windows 8
【问题描述】
Why am I getting an error accessing a multivalue parameter in Python at ArcGIS for Desktop 10.1?
Article ID: 42668
Software:
ArcGIS for Desktop Advanced 10.1, 10.2
ArcGIS for Desktop Standard 10.1, 10.2
ArcGIS for Desktop Basic 10.1, 10.2
Platforms:
Windows XP, Vista, Windows 7, Windows 8
【问题描述】
Why am I getting an error accessing a multivalue parameter in Python at ArcGIS for Desktop 10.1?
1 个回复
EsriSupport
赞同来自:
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:
============
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:
============
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
arcpy.AddMessage ("table name: " + str(tbl))
i += 1
============
【创建及修改时间】
[i]Created: 6/9/2014
Last Modified: 6/30/2014
【原文链接】
http://support.esri.com/en/kno ... 42668
要回复问题请先登录或注册