How to open a file with chinese name in python.

Posted by mahendraliya on Stack Overflow See other posts from Stack Overflow or by mahendraliya
Published on 2011-03-17T08:00:43Z Indexed on 2011/03/17 8:10 UTC
Read the original article Hit count: 141

Filed under:

I am trying to open a file in "w" mode with "open()" function in python.

The filename is : ?????.jpg.

The open function fails with this filename but succeeds with normal files.

How can I open a file with names which are not in English in python?

My code is as follows:

try:
    filename = urllib.quote(filename.encode('utf-8'))
    destination = open(filename, 'w')
    yield("<br>Obtained the file reference")
except:
    yield("<br>Error while opening the file")

I always get "Error while opening the file" for non-english filenames.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about python