I just want to count the values in a list (NEIGHBORS) for each object in my layer and put the result in a column (NUMBER).
My code is not working
from qgis.PyQt.QtCore import QVariant
test = iface.activeLayer()
v1 = QgsVectorLayer("NUMBER")
with edit (v1):
for f in v1.getFeatures():
f ["NUMBER"] = f[len('NEIGHBORS')]
v1.updateFeature(f)
and has the following error.
Traceback (most recent call last):
File "C:\PROGRA~1\QGIS31~1.15\apps\Python39\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "<string>", line 36, in <module>
File "C:\PROGRA~1/QGIS31~1.15/apps/qgis-ltr/./python\qgis\core\additions\edit.py", line 38, in __enter__
assert self.layer.startEditing()
AssertionError
Do you have an idea?
len(f['NEIGHBORS'].split(','))
, otherwise it will just return the length of the string