Using the layer_by_name() function can cause an Index out of bounds error if the layers_by_name call returns no results. Suggest confirming length of result > 0 before trying to return result 0.
def layer_by_name(name):
"""
Return a layer from QGIS using its name.
:param name: The name of the layer
:return: A single layer with the given layer name
"""
return layers_by_name(name)[0]
Using the layer_by_name() function can cause an Index out of bounds error if the layers_by_name call returns no results. Suggest confirming length of result > 0 before trying to return result 0.
def layer_by_name(name): """ Return a layer from QGIS using its name. :param name: The name of the layer :return: A single layer with the given layer name """ return layers_by_name(name)[0]