0

layer.renameAttribute(0,'xxx') Traceback (most recent call last): File "", line 1, in AttributeError: 'QgsVectorLayer' object has no attribute 'renameAttribute'

Can you get me solution for this error?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338

1 Answers1

2

I had the same issue. Try this piece of code. It worked for me.

layer = iface.activeLayer()
for field in layer.pendingFields():
    if field.name() == 'old':
        with edit(layer):
            idx = layer.fieldNameIndex(field.name())
            layer.renameAttribute(idx, 'new')
raosaeedali
  • 707
  • 6
  • 21