I want to import several spatial csv files (points) into QGIS.
The path to the folder, where the csv files are located is stored in the variable "Folder_Path". The file names are stored in a list.

It seems to me, that the only way to create a memory layer in this case is with a uri. But the uri in the syntax of QgsVectorLayer(uri, 'Test', 'delimitedtext') has instead of a forward slash "/" a backward slash "\". Replacing the forward slash with a backward slash doesn't work with my code:

Folder_Path = QFileDialog.getExistingDirectory(caption="Pick Folder 'Import_QGIS'.")

#Folder_Path for uri
Folder_Path_uri = Folder_Path.replace("/", "\")

Result is SyntaxError: EOL while scanning string literal

How can I let Python know, that the "\" is just a character and not an escape? Or is there a better way to go about adding csv files?


Your \ is hiding the closing " so you need to use \\ - but python shouldn't care about the slashes in the path.


Not the answer you're looking for? Browse other questions tagged or ask your own question.