[GIS] How to Check if a Layer is PRESENT or ABSENT in a Project via PyQGIS

pyqgispythonqgis

In QGIS, what is the simplest python code (least possible) to verify if a particular layer is PRESENT or ABSENT in the Map Layers list?

NOTE: The script shouldn't trip an error IF the layer is ABSENT.

Best Answer

len(QgsMapLayerRegistry.instance().mapLayersByName('the_Map_Layer_in_question')) != 0

Trueif layer exists, otherwise False

Related Question