Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python SyntaxError:(unicode错误)'UnicodeScape'编解码器无法解码位置0-1中的字节:格式错误\N字符转义_Python - Fatal编程技术网

Python SyntaxError:(unicode错误)'UnicodeScape'编解码器无法解码位置0-1中的字节:格式错误\N字符转义

Python SyntaxError:(unicode错误)'UnicodeScape'编解码器无法解码位置0-1中的字节:格式错误\N字符转义,python,Python,抱歉,我知道有类似的线索,但我仍然没有任何运气!我是Python的新手&试图解释一位同事编写的代码 我不断收到UnicodeScape错误: 我知道这与Python解释“用户”的方式有关,但在添加r时运气不太好。或者加上双斜杠,我可能放错地方了 感谢您的帮助 folder_year = str(datetime.today().year) #Save current year as a variable folder_month = str((datetime.today()- relative

抱歉,我知道有类似的线索,但我仍然没有任何运气!我是Python的新手&试图解释一位同事编写的代码

我不断收到UnicodeScape错误:

我知道这与Python解释“用户”的方式有关,但在添加r时运气不太好。或者加上双斜杠,我可能放错地方了

感谢您的帮助

folder_year = str(datetime.today().year) #Save current year as a variable
folder_month = str((datetime.today()- relativedelta(months=1)).strftime("%B")) #Save current month as a variable

yr_directory = "C:\\Users\\Beva\\Documents\\Lettings Index\\"+str(folder_year) #Current year folder link

full_directory = "C:\\Users\\Beva\\Documents\\Lettings Index\\"+str(folder_year)+"\\"+str(folder_month)+"\New Lets Old" #Current month for current year folder link
您可以使用原始字符串添加r,如下所示:

>>> r'\New Lets Old'
'\\New Lets Old'
或者自己避开反斜杠:

>>> '\\New Lets Old'
'\\New Lets Old'
出现错误是因为Python试图解释\N。。。部件作为Unicode代码点:

>>> '\N{LATIN CAPITAL LETTER B}\N{LATIN SMALL LETTER E}\N{LATIN SMALL LETTER V}\N{LATIN CAPITAL LETTER A}'
'BevA'

哎呀,我原来无法将问题中的代码向右滚动,也看不到\N来自哪里

这是\N in \New Lets旧字符串,而不是\U@VPfB,对,我想我的浏览器出现了延迟,我无法向右滚动查看,因此我认为错误消息中的\N是打字错误或其他什么
>>> '\N{LATIN CAPITAL LETTER B}\N{LATIN SMALL LETTER E}\N{LATIN SMALL LETTER V}\N{LATIN CAPITAL LETTER A}'
'BevA'