SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UX
程序员文章站
2022-06-15 13:40:31
...
win下运行python报错:
SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
$ "D:/Program Files/Python 3.5/python.exe" c:/Users/Administrator/Desktop/py_memcache/py_memcache/set_memcache.py
File "c:/Users/Administrator/Desktop/py_memcache/py_memcache/set_memcache.py", line 3
f = open("C:\Users\Administrator\Desktop\py_memcache\py_memcache\keys.txt", "r")
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
解决办法
在字符串前加一个字母 r,如下:
f = open(r”C:\Users\Administrator\Desktop\py_memcache\py_memcache\keys.txt”, “r”)
在字符串前加个 r 是为了告诉编译器这个string是个raw string,不要转义。
或者 将 \ 改为 /
上一篇: javascript 继承
下一篇: JavaScript继承
推荐阅读
-
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UX
-
报错:SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated
-
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UX
-
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UX
-
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UX
-
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UX
-
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UX
-
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UX
-
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UX
-
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UX