Python not opening Japanese filenames
Question: I've been working on a python script to open up a file with a unicode name
(Japanese mostly) and save to a randomly generated (Non-unicode) filename in
Windows Vista 64-bit, and I'm having issues... It just doesn't work, it works
fine with non-unicode filenames (Even if it has unicode content), but the
second you try to pass a unicode filename in - it doesn't work.  
Here's the code:

    
    
    try:
        import sys, os
        inpath = sys.argv[1]
        outpath = sys.argv[2]
        filein = open(inpath, "rb")
        contents = filein.read()
        fileSave = open(outpath, "wb")
        fileSave.write(contents)
        fileSave.close()
    
        testfile = open(outpath + '.test', 'wb')
        testfile.write(inpath)
        testfile.close()
    
    except:
        errlog = open('G:\\log.txt', 'w')
        errlog.write(str(sys.exc_info()))
        errlog.close()
    

  
  
And the error:

    
    
    (<type 'exceptions.IOError'>, IOError(2, 'No such file or directory'), <traceback object at 0x01092A30>)
    


Answer: You have to convert your `inpath` to unicode, like this:

    
    
    inpath = sys.argv[1]
    inpath = inpath.decode("UTF-8")
    filein = open(inpath, "rb")
    

I'm guessing you are using Python 2.6, because in Python 3, all strings are
unicode by default, so this problem wouldn't happen.

