1

I'm trying to write a "simple" plugin as training and to automate a task repetitive task as well. I would like to have the map layer hardcoded instead of make sure you select the correct one but if I use mapLayersByName it adds [ and ] to start and end of layer which makes it think its a list. I can fix this by using Layer[0].getFeatures() instead of normally using Layer.getFeatures()

What causes this?

Layer = QgsProject.instance().mapLayersByName('Parry Sound FDSA Boundaries')
layer = iface.activeLayer()

print(Layer)
[<qgis._core.QgsVectorLayer object at 0x000001D610F0AD38>]

print(layer)
<qgis._core.QgsVectorLayer object at 0x000001D610F0AD38>
4

It is by design

Retrieve a list of matching registered layers by layer name.

You could have several layers having the same name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.