为什么在文件路径中出现Unicode转义的SyntaxError? [英] Why do I get a SyntaxError for a Unicode escape in my file path?
本文介绍了为什么在文件路径中出现Unicode转义的SyntaxError?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要访问的文件夹称为python,位于我的桌面上.
The folder I want to get to is called python and is on my desktop.
当我尝试到达它时出现以下错误
I get the following error when I try to get to it
>>> os.chdir('C:\Users\expoperialed\Desktop\Python')
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
推荐答案
您需要使用 raw 字符串,将斜杠加倍或使用正斜杠:
You need to use a raw string, double your slashes or use forward slashes instead:
r'C:\Users\expoperialed\Desktop\Python'
'C:\\Users\\expoperialed\\Desktop\\Python'
'C:/Users/expoperialed/Desktop/Python'
在常规python字符串中,\U
字符组合表示扩展的Unicode代码点转义.
In regular python strings, the \U
character combination signals a extended Unicode codepoint escape.
对于 查看全文