Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 属性错误:';列表';对象没有属性';更新项';_Python_Arcpy - Fatal编程技术网

Python 属性错误:';列表';对象没有属性';更新项';

Python 属性错误:';列表';对象没有属性';更新项';,python,arcpy,Python,Arcpy,我正在使用arcpy进行地图自动化工作 我需要根据添加到mxd的图层在地图布局上添加图例。我使用的代码如下(如教程所示): 但每次运行此代码时,都会出现以下错误: Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> AttributeError: 'list' object has no attribute 'updateItem'

我正在使用arcpy进行地图自动化工作

我需要根据添加到mxd的图层在地图布局上添加图例。我使用的代码如下(如教程所示):

但每次运行此代码时,都会出现以下错误:

Runtime error 
   Traceback (most recent call last):
   File "<string>", line 1, in <module>
   AttributeError: 'list' object has no attribute 'updateItem'
运行时错误
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
AttributeError:“list”对象没有属性“updateItem”
是什么导致出现此错误

是什么导致出现此错误

我对arcpy不太熟悉,但似乎
ListLayoutElements()
返回的第0个元素是一个确实没有
updateItem()方法的列表


您可能希望将
.append()
添加到列表中,或者您可能希望使用不同类型的对象。

您的代码与ArcGIS帮助示例相同, 我测试了示例代码,它运行正常。

顺便问一下,我想知道你是否粘贴了自己的代码。否则,您可能会在第2、4、6行而不是最后一行遇到问题。

正如用户2357112所建议的,您最好用干净的代码再试一次。
或者您可以通过在行前打印类型(图例)
确认变量“图例”的类型
legend.updateItem(lyrFile,styleItem)
legend
是一个列表,因此您可以使用
append
方法向其中添加元素。鉴于您发布的代码有语法错误(从末尾算起的第三行),最有可能的问题是在Python解释器中键入代码时出错。再试一次。似乎缺少一个右括号。。从末尾算起的第三行。
Runtime error 
   Traceback (most recent call last):
   File "<string>", line 1, in <module>
   AttributeError: 'list' object has no attribute 'updateItem'