unicode error preventing creation of text file

前端 未结 2 545
难免孤独
难免孤独 2021-01-24 04:36

What is causing this error and how can I fix it?

(unicode error) \'unicodeescape\' codec can\'t decode bytes in position 2-3: truncated \\UXXXXXXXX escape

2条回答
  •  长情又很酷
    2021-01-24 05:09

    \U is being treated as the start of a Unicode literal. Use a raw string (a preceding r) to prevent this translation:

    >>> 'C:\Users'
      File "", line 1
    SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
    >>> r'C:\Users'
    'C:\\Users'
    

提交回复
热议问题