I want to delete specific columns in the attribute table of my layer:
except for the "LAYER"
Column.
This is my code:
clip = processing.runAndLoadResults("native:clip",
{ 'INPUT': union['OUTPUT'],
'OVERLAY': dissolved['OUTPUT'],
'OUTPUT': 'TEMPORARY_OUTPUT',
})
# field names to be deleted
fields = ['fid_2',
'fid',
'Phasenr_2',
'fid_3',
'Phasename',
'layer',
'path']
# get field ids from field names
field_ids = [clip.field().indexFromName(f) for f in fields]
# delete the attribute using their index
clip.dataProvider().deleteAttributes(field_ids)
clip.updateFields()
Error:
Traceback (most recent call last):
File "C:\PROGRA~1\QGIS32~1.0\apps\Python39\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "<string>", line 69, in <module>
File "<string>", line 69, in <listcomp>
AttributeError: 'dict' object has no attribute 'field'