Setting feature attribute by name via QGIS python api?
QGIS can use field names and indexes:
feature['fieldname'] = 10
feature[1] = 10
Make sure you are in edit mode before you do anything on the layer:
layer.startEditing()
feature['fieldname'] = 10
layer.updateFeature(feature)
#Call commit to save the changes
layer.commitChanges()