我試圖打開一個文件,我只是意識到,py有麻煩與我的用戶名(這是在俄羅斯)。有關如何正確解碼/編碼這個讓閒暇快樂的建議?處理多語言目錄(Python)
我用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 =開放(U「d:\用戶\Эрик\下載\ TEMP .XML 「.encode( 」MBCS「), 」R「)
回溯(最近通話最後一個): 文件 」「,1號線,在 XMLFILE =開放(U」 d:\用戶\Эрик\下載\ temp.xml「.encode(」mbcs「),」r「) IOError:[Errno 22] inval ID模式('r')或文件名:'D:\ Users \ Y?ee \ Downloads \ temp.xml'