【发布时间】:2010-06-20 18:11:17
【问题描述】:
我正在尝试打开一个文件,但我刚刚意识到 py 我的用户名有问题(它是俄语)。有关如何正确解码/编码以使空闲快乐的任何建议?
我正在使用 py 2.6.5
xmlfile = open(u"D:\\Users\\Эрик\\Downloads\\temp.xml", "r")
Traceback (most recent call last):
File "<pyshell#23>", line 1, in <module>
xmlfile = open(str(u"D:\\Users\\Эрик\\Downloads\\temp.xml"), "r")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 9-12: ordinal not in range(128)
os.sys.getfilesystemencoding() 'mbcs'
xmlfile = open(u"D:\Users\Эрик\Downloads\temp.xml".encode("mbcs"), "r")
Traceback(最近一次调用最后一次): 文件“”,第 1 行,在 xmlfile = open(u"D:\Users\Эрик\Downloads\temp.xml".encode("mbcs"), "r") IOError: [Errno 22] 无效模式 ('r') 或文件名:'D:\Users\Y?ee\Downloads\temp.xml'
【问题讨论】: