I have the following script that i'd like to make into a QGIS toolbox.

# -*- coding: utf-8 -*-
##shpgen = name
##Fichier_CSV = file
##Chemin_de_sortie =  folder
import sys
import re 
import csv
from PyQt4.QtCore import *
from PyQt4.QtGui import * 
import os.path

final_list = []

with open(Fichier_CSV, "rU") as s:  
    reader_tables = csv.DictReader(s,delimiter=';')
    liste_tables = list(reader_tables)
    l_tables = [i['table'] for i in liste_tables]
    l_tables = set(l_tables)
    for table in l_tables:
        l1 = [line for line in liste_tables if line['table'] == table] 
        geometry = l1[1]['geometry']
        layer_mem = QgsVectorLayer(geometry+"?crs=epsg:2154",table,"memory")
        QgsVectorFileWriter.writeAsVectorFormat(layer_mem,os.path.joint(Chemin_de_sortie+"{}".format(table)),"utf-8",None,"ESRI Shapefile",False)
        layer_path = os.path.join(Chemin_de_sortie,table+".shp")
        shp = QgsVectorLayer(layer_path,table,'ogr')
        pr = shp.dataProvider()
        for field in l1:
            if field['type'] != 'Double':
        del layer_mem,shp,pr

The script doesnt execute for some reason. Could someone hep me out?


I removed # -*- coding: utf-8 -*- and now i have the following msg:

name 'Fichier_CSV' is not defined See log for more details
  • Bottom right corner of QGIS, the small comic strip bubbles. Did you restart QGIS just in case? – etrimaille Dec 18 '17 at 16:21
  • 2017-12-18T17:32:04 2 Uncaught error while executing algorithm Traceback (most recent call last): File "C:/PROGRA~1/QGIS2~1.14/apps/qgis-ltr/./python/plugins\processing\core\GeoAlgorithm.py", line 203, in execute self.processAlgorithm(progress) File "C:/PROGRA~1/QGIS2~1.14/apps/qgis-ltr/./python/plugins\processing\script\ScriptAlgorithm.py", line 323, in processAlgorithm exec((script), ns) File "<string>", line 20, in <module> NameError: name 'Fichier_CSV' is not defined – user3327567 Dec 18 '17 at 16:34
  • @user3327567 - Make sure there are no spaces in your parameters. E.g. change ##Fichier_CSV = file to ##Fichier_CSV=file – Joseph Dec 19 '17 at 10:22
  • @user3327567 - I'm assuming you solved this issue you were having, in which case you should post an answer :) – Joseph Dec 20 '17 at 9:53
  • oops! i totally forgot to post the solution. It was the spaces like you said in the comment above. – user3327567 Dec 20 '17 at 9:55