最佳答案
我在Windows 7机器上使用Python 3.1。俄语是默认的系统语言,utf-8是默认的编码。
查看前一个问题的答案,我尝试使用"codecs"模块给我一点运气。以下是一些例子:
>>> 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“翻译”的事实。一些文件夹,如“用户”;文件夹,变成俄语(尽管输入"用户"仍然是正确的路径),所以我在Python31文件夹中尝试了它。不过,运气还是不好。什么好主意吗?