I am trying to separate a string value from a field and then put it into its releated Field.
The field name are characters in the string and its value is the number.
"Field"=PT 100BC 20cd 19 is the string value
PT= 100, BC=20 cd=19.
the string is irregular.
the column names are the characters in the string and number is the value associated with it.
I have so far done this.
from qgis.core import *
import qgis.utils
inlayer=iface.activeLayer()
inlayer.selectByExpression('"TRTMTHD1"=\'PLANT\'or "TRTMTHD1"=\'NATURAL\' ')
selection=inlayer.selectedFeatures()
for s in selection:
d=(sl.split() for sl in s)
If they do the split the result is PT, 100BC, 20CD which I do not want.
Which command do I use to split the value in field column and then update the record?
After I run this
{from qgis.core import * import qgis.utils
layer=iface.activeLayer() fc=layer.featureCount() f_list=[] for i in range(0,fc): feat=layer.getFeature(i) f_list.append(feat['SPCOMP'])
field_list=[] for f in layer.fields(): if len(f.name())==2: field_list.append(f.name())
layer.selectByExpression('"TRTMTHD1"=\'PLANT\'or "TRTMTHD1"=\'NATURAL\' ') selection=layer.selectedFeatures()
for string in f_list: if string!=None: for fn in field_list: string=string.replace(fn,',' + fn)
list_of_field_values=(string.split(',') for string in f_list)
for fvl in list_of_field_values:
if fvl !='':
fd,vl=fvl.split(' ')
print('field=',fd,'value=',vd)}
I get AttributeError: 'list' object has no attribute 'split'