lundi 17 février 2020

Python dictionary if statement when values are not quoted

I have what seems to be a dictionary, the keys are quoted but the values are not. I want to create an if statement that will find values that are similar LIKE a given wording and return the KEY that the value belongs to. I’m in QGIS, I’ve added a google web map among others, I want a script that will single out the QGSRasterLayer.

from qgis.core import QgsRasterLayer, QgsProject
mylistlayers = QgsProject.instance().mapLayers()

print (mylistlayers)
#prints{'Google_Satellite_Hybrid_f1844874_b30f_445b_ab2e_c69426f21eef': <qgis._core.QgsRasterLayer object at 0x000001AC9FC19F78>

print (mylistlayers.values())
#prints    #dict_values([<qgis._core.QgsRasterLay #er object at 0x000001AC9FC19F78>])

if [qgis._core.QgsVectorLayer] in mylistlayers.values():
   print(999)
#    nothing prints

if [qgis._core.QgsVectorLayer] not in mylistlayers.values():
   print(-111)
#    -111prints

Aucun commentaire:

Enregistrer un commentaire