*Python 3.7 and QGIS 3.6
I have a program that loads multiple layers, and now I need to select different layers to edit. Before I was managing fine with iface.activeLayer(), but now that I have multiple layers this is no longer an option.
My current code - additional layers are loaded later:
layer = iface.addVectorLayer(in_file, name, 'ogr') iface.mapCanvas().refreshAllLayers() layer = iface.mapCanvas().layer(0) layer.startEditing()
This results in the following error:
AttributeError: 'NoneType' object has no attribute 'startEditing'
Interestingly, if I run the code when there is already a layer loaded, it works. This isn't an actual fix though, as it's not realistic for me to have a layer pre-loaded each time I run the code.