I am trying to develop a script to export selected features on a layer to enable some automation.
So far I have used this formula to import a layer and run a query. This ends up with features being selected on the layer.
See result:
All good so far.
I now try to use the below script, found in a previous similar question: QGIS Export Shapefile using PyQgis
It worked for the users in the post, however this returns the following error for me:
I am quite new to Python so am not quite sure what's wrong. It is saying name 'i' is not defined, but I'm not sure what 'i' is trying to refer to?
I'm using QGIS 2.18.20.



_writer = QgsVectorFileWriter.writeAsVectorFormat(layer, 'd:/junk/test.shp', "UTF-8", layer.crs(), "ESRI Shapefile", onlySelected=True)– GeorgeC Sep 15 '19 at 23:51