Wednesday, 19 September 2018

Renaming field in attribute table via PyQGIS?



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

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...