I have the code :
from qgis.core import QgsMapLayerRegistry
vl = QgsMapLayerRegistry.instance().mapLayersByName('pl')[0]
iface.setActiveLayer(vl)
When I type in console after loading QGIS, no error. But, when I put the code in startup.py, so automatically QGIS will execute the code in startup.py, I get error. The error : "list index out of range"
What is wrong for the code?