I have a file with the following path : D:/bar/クレイジー・ヒッツ!/foo.abc
I am parsing the path from a XML file and storing it in a variable called path in the
Provide the filename as a unicode string to the open call.
How do you produce the filename?
Add a line near the beginning of your script:
# -*- coding: utf8 -*-
Then, in a UTF-8 capable editor, set path to the unicode filename:
path = u"D:/bar/クレイジー・ヒッツ!/foo.abc"
Retrieve the contents of the directory using a unicode dirspec:
dir_files= os.listdir(u'.')
Open the filename-containing-file using codecs.open to read unicode data from it. You need to specify the encoding of the file (because you know what is the “default windows charset” for non-Unicode applications on your computer).
Do a:
path= path.decode("utf8")
before opening the file; substitute the correct encoding if not "utf8".