As far as I see, on
QgsMapLayerRegistry.instance() there is a method to select layers:
and the method
respectively, wich accesses a layer by its id.
As the name says,
mapLayersByName() selects layers by their name in the legend, wich causes scripts or plugins to fail if a user renames a layer/table (i.e. renaming a table '160520_parcels' to 'Parcels').
So is there a way to access a layer by the name of it's origining table in PyQGIS?
something like ...
def selectLayerByOriginalName(tablename): # return layers whose orininal names start with 'tablename' llist =  for l in QgsMapLayerRegistry.instance().mapLayers().values(): if tablename in l.id(): if l.id().index(tablename) == 0: llist.append(lyr) return llist
... works, but is there a more convenient approach?