I would like to use pure Python to export the attribute table as csv. For the variable data, I need a list that will read the whole attribute table. Is that possible?
import csv
layer = iface.activeLayer()
header = [field.name() for field in layer.fields()]
print(header)
data = [
#Can I get the attribute table of the active layer here as a list
]
with open('//home/lissiklaus/Downloads/tmp/csv/countries.csv', 'w', encoding='UTF8', newline='') as f:
writer = csv.writer(f)
# write the header
writer.writerow(header)
# write multiple rows
writer.writerows(data)