I have some vector shape files with many columns. I need to change the name of each column in the header from the old name to a more generic "Img1", "Img2", "Img3", etc progressively, starting from column #5 and leaving the name of columns 1 to 4 unchanged.
I wrote this Python code to be used with QGIS but it doesn't work.
layer = iface.activeLayer() nImg = 1 nCol = len(layer.pendingFields()) cont = (5,nCol) for field in cont: with edit (layer): oldName = layer.fieldNameIndex(field.name()) newName = "Img" + str(nImg) layer.renameAttribute(oldName, newName) nImg = + 1
The error is
oldName = layer.fieldNameIndex(field.name()) AttributeError: 'int' object has no attribute 'name'
I tried also changing
with edit (layer)
and unindenting the rows, but it doesn't work anyway.