And would like to iterate over the attribute table returning only two field values. Isn't there a way to limit the values returned by
getFeatures so all attributes does not have to be read? This work but seems convoluted:
layer = iface.activeLayer() fields_to_return = ['KKOD','KATEGORI'] for feat in layer.getFeatures(): print([feat[f] for f in fields_to_return]) [414, 'Kommun'] [414, 'Kommun'] [414, 'Kommun'] ...
In ArcGIS I would do:
with arcpy.da_SearchCursor(r'C:\data.gdb\ak_riks',fields_to_return) as cursor: for row in cursor: print(row)