I am using this code in the QGIS Python console to update a feature value. However, in order to get the feature value to change, I have to run it twice. Suggestions on why this is happening?
layer = iface.activeLayer()
layerFields = layer.fields()
fieldIndex = layerFields.indexFromName("February")
feature = layer.selectedFeatures()
featureID = feature[0].id()
label = 'G'
layer.startEditing()
layer.changeAttributeValue(featureID, fieldIndex, label)
layer.commitChanges()
print(fieldIndex)
for f in feature:
print(f.attributes())
1st:
exec(open('C:/..../AppData/Local/Temp/tmpb78pyjoe.py'.encode('utf- 8')).read())
3
[10, 440631, NULL, NULL]
2nd:
exec(open('C:/..../AppData/Local/Temp/tmp_9u0wl9z.py'.encode('utf-8')).read())
3
[10, 440631, NULL, 'G']