This question has been asked before but I couldn't get the solution to work. I have a shapefile with lots of empty columns and I would like to remove them all with a script or some tools.
This is the script that was posted as the solution to the other thread.
lyr = iface.activeLayer()
lstDelete = []
for idx in lyr.dataProvider().attributeIndexes():
uv = lyr.dataProvider().uniqueValues( idx )
if not uv:
lstDelete.append( idx )
lyr.dataProvider().deleteAttributes( lstDelete )
# Update the layer structure
lyr.updateFields()
When I try it both on Windows 2.18.1 and Mac 2.18.0 I get no change to my active layer.