欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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继承