当我从组合框调用层时,抛出这样的错误。 执行Python代码时出错:
TypeError:“dict_values”对象不支持索引 回溯(最近一次呼叫最后一次): selectedLayer=层[selectedLayerIndex1]。层() TypeError:“dict_values”对象不支持索引
Python版本:3.7.0(v3.7.0:1bf9cc5093,2018年6月27日,04:59:51)[MSC v.1914 64位(AMD64)] QGIS版本:3.4.15-Madeira Madeira,e83d02e274
代码 SelectedLayerIndex 1=self.dlg.comboBox.currentIndex()
selectedLayer=层[selectedLayerIndex1]。层()
qgis版本:qgis版本:3.4.15-Madeira Madeir
如果要使用索引,必须首先迭代层并将其添加到LayerList中。只有在thar之后,您才能使用索引并从列表中选择图层(使用索引)
在def
run(self)
中使用此代码:我不确定具体的问题是什么,但经过一些研究,在Python 3中,对字典调用'values()'方法似乎不会返回列表,而是返回'dict_values'对象。
所说的“dict_values”对象不支持索引访问,请查看其文档以了解更多信息
相关问题 更多 >
编程相关推荐