I want to run the following script in QGIS
from qgis.core import * from qgis.utils import * from PyQt4.QtCore import * inLayer = iface.activeLayer() with open('iso_codes.txt') as f: codes = f.readlines() for isoCode in codes: #exp = QgsExpression('"ISO_CODE" = \'AF\'') # THIS WORKS exp = QgsExpression('"ISO_CODE" = \'%s\'' % isoCode) # THIS DOES NOT WORK request = QgsFeatureRequest( exp ) fipsCode = '' for feature in inLayer.getFeatures( request ): fips = feature['FIPS_CODE'] if fipsCode != fips: fipsCode = fips print '%s, %s' % (isoCode, fipsCode)
Using '"ISO_CODE" = \'AF\'' as argument the script works till the end.
Using '"ISO_CODE" = \'%s\'' % isoCode as argument the script doesn't go into the for loop.
I've tried to use inLayer.setSelectedFeatures() at the end of the for loop, but this did not help.