I found a script for loading several csv files into QGIS and modified it for .xyz Data. Yesterday on one Computer it worked and today on a different Computer it's not working anymore.

Is there something wrong with the code?

I tried to use the following code in the python console

import glob, os

path = "C:\Users\J\Desktop\xyz_data"


for file in glob.glob("*.xyz"):
    uri = "file:///" + path + file + "?delimiter=%s&crs=epsg:4647&xField=%s&yField=%s" % (" ", "field_1", "field_2")
    name = file.replace('.xyz', '')
    lyr = QgsVectorLayer(uri, name, 'delimitedtext')

After the "path" line I get the following error message:

Traceback (most recent call last): File "C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\code.py", line 63, in runsource code = self.compile(source, filename, symbol) File "C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\codeop.py", line 168, in call return _maybe_compile(self.compiler, source, filename, symbol) File "C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\codeop.py", line 99, in _maybe_compile raise err1 File "C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\codeop.py", line 87, in _maybe_compile code1 = compiler(source + "\n", filename, symbol) File "C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\codeop.py", line 133, in call codeob = compile(source, filename, symbol, self.flags, 1) File "", line 1 SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape os.chdir(path) Traceback (most recent call last): File "C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\code.py", line 90, in runcode exec(code, self.locals) File "", line 1, in NameError: name 'path' is not defined

When I enter the last line of the Code into the python console nothing happens. No layers are uploaded and I don't get error Messages.


1 Answer 1



path = r"C:\Users\J\Desktop\xyz_data"

instead of:

path = "C:\Users\J\Desktop\xyz_data"
  • I edited my question
    – DGIS
    Commented Jan 6, 2020 at 10:44
  • 1
    I've rolled back your question because it appears my answer was correct i.e. when you fixed that the error you were getting no longer occurred. You can ask a new question for your new error.
    – PolyGeo
    Commented Jan 6, 2020 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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