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

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

程序员文章站 2022-06-15 13:39:49
...

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

最近在学习python,输入如下代码

f=open('C:\Users\Shen Xue\Desktop\read.txt','r')

报错

File "<ipython-input-12-62ddc119b355>", line 1
    f=open('C:\Users\Shen Xue\Desktop\read.txt','r')
          ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

【\U】是八进制的转义符,所以,就会出现以上的错误提醒。utf-8是告诉python interpret如何解释字符串的编码,所以前面写的是utf-8。

修改

f=open(r'C:\Users\Shen Xue\Desktop\read.txt','r')

问题完美解决啦!!!