Hi All,<br><br>I'm trying to write a short plugin and I've been using the PyConsole to test code snip-its. I'm having trouble deleting a column that I've created in a table (even in the attribute table GUI - the delete column button is inactive even though the add table column is active and the layer is editable). Here's the code I've used to create the column;<br>
<br>import qgis.core<br>import qgis.gui<br>import PyQt4.QtCore<br>import PyQt4.QtGui<br>vlayer = qgis.utils.iface.activeLayer()<br>provider = vlayer.dataProvider()<br>feat = QgsFeature()<br>newField = QgsField("azimuth",QVariant.Double)<br>
provider.addAttributes([newField])<br>newFieldIndex = provider.fieldNameIndex(newField.name())<br>vlayer.commitChanges()<br><br>When I try to use the following code to delete the column, the function returns 'false';<br>
<br>provider.deleteAttributes([newFieldIndex])<br><br>I had a look at the API and apparently some constant called 'QgsAttributeIds', an 'int', is expected by the deleteAttributes() function. I've tried a few variations of this with no success and according to the API it seems that all the deleteAttributes() function does is to return 'false' (<a href="http://www.qgis.org/api/qgsvectordataprovider_8cpp-source.html#l00104">http://www.qgis.org/api/qgsvectordataprovider_8cpp-source.html#l00104</a>). What is the correct Python code to delete a column in the PyConsole? Thanks,<br>
<br>Chris<br>