我在Windows 7机器上使用Python 3.1。俄语是默认的系统语言,utf-8是默认的编码。
看看前面一个问题的答案,我尝试使用“编解码器”模块给我一点运气。以下是一些例子:
>>> g = codecs.open("C:\Users\Eric\Desktop\beeline.txt", "r", encoding="utf-8")
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-4: truncated \UXXXXXXXX escape (<pyshell#39>, line 1)
>>> g = codecs.open("C:\Users\Eric\Desktop\Site.txt", "r", encoding="utf-8")
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-4: truncated \UXXXXXXXX escape (<pyshell#40>, line 1)
>>> g = codecs.open("C:\Python31\Notes.txt", "r", encoding="utf-8")
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 11-12: malformed \N character escape (<pyshell#41>, line 1)
>>> g = codecs.open("C:\Users\Eric\Desktop\Site.txt", "r", encoding="utf-8")
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-4: truncated \UXXXXXXXX escape (<pyshell#44>, line 1)
我的最后一个想法是,我认为这可能是因为Windows“翻译”了一些文件夹,比如“users”文件夹,变成了俄文(尽管输入“users”仍然是正确的路径),所以我在Python31文件夹中尝试了它。不过,运气还是不好。什么好主意吗?