I use iface.activeLayer()
intensively. Therefore, when I open QGIS, firstly I use the following script in QGIS Python Editor not to enter iface.activeLayer()
everytime.
from qgis.utils import iface
L = iface.activeLayer()
def activeLayerChanged():
L = iface.activeLayer()
iface.currentLayerChanged.connect(activeLayerChanged)
I thought it would work if I added it to startup.py
file. I tried to add the script to startup.py
but I got error: name 'L' is not defined
.
How can I assing iface.activeLayer()
to L
(or any single-letter variable) when starting QGIS, so that everytime I enter L
, I can get the active layer?
a=1
, thena
is not found in QGIS