Just pass open() unicode string for the file name:
In Python 2.x:
>>> open(u'someUnicodeFilenameλ') <open file u'someUnicodeFilename\u03bb', mode 'r' at 0x7f1b97e70780>
In Python 3.x, all lines are Unicode, so there is nothing in it.
As always, note that the best way to open a file always uses the with statement in combination with open() .
Edit: Regarding os.listdir() , the tip is changing again, in Python 2.x you have to be careful:
os.listdir (), which returns file names, causes a problem: should it return a Unicode version of file names or should it return 8-bit strings containing encoded versions? os.listdir () will do both, depending on whether the directory path was specified as an 8-bit string or a Unicode string. If you pass a Unicode string as a path, the file names will be decoded using the file system encoding, a list of Unicode strings will be returned, and transmitting an 8-bit path will return 8-bit versions of the file names.
A source
In short, if you want Unicode to come out, put Unicode in:
>>> os.listdir(".") ['someUnicodeFilename\xce\xbb', 'old', 'Dropbox', 'gdrb'] >>> os.listdir(u".") [u'someUnicodeFilename\u03bb', u'old', u'Dropbox', u'gdrb']
Please note that the file will still be open anyway - it will not display well inside Python, since it will be an 8-bit string, but it will still work.
open('someUnicodeFilename\xce\xbb') <open file 'someUnicodeFilenameλ', mode 'r' at 0x7f1b97e70660>
Under 3.x, as always, it is always Unicode.