How can I rename a field in PyQGIS?
I tried:
for field in layer.pendingFields():
if field.name() == 'old':
layer.startEditing()
oldname = field.name()
field.setName('new')
newname = field.name()
print(u'Old name: {}, New name: {}'.format(oldname,newname))
layer.commitChanges()
This code print 'Old name: old, New name: new', but in attribute table is field name still 'old'.
No comments:
Post a Comment