' \xc \xe ccodecs open('utfdata'' 'encoding='utf- 'read( ' \xc \xe cprint codecs open('utfdata'' 'encoding='utf- 'read(aabec reads decode print to view for more unicode detailssee earlier sections of this and python manuals unicode filenames and streams in closingthis section has focused on the encoding and decoding of unicode text file contentbut python also supports the notion of non-ascii file names in factthey are independent settings in syswhich can vary per python version and platform ( returns ascii for the first of the following on windows)import sys sys getdefaultencoding()sys getfilesystemencoding(('utf- ''mbcs'file contentnames filenamestext versus bytes filename encoding is often nonissue in shortfor filenames given as unicode text stringsthe open call encodes automatically to and from the underlying platform' filename conventions passing arbitrarily pre-encoded filenames as byte strings to file tools (including open and directory walkers and listersoverrides automatic encodingsand forces filename results to be returned in encoded byte string form too--useful if filenames are undecodable per the underlying platform' conventions ( ' using windowsbut some of the following may fail on other platforms) open('xxx\ '' ' write('\xa \ ' close(print(open('xxx\ 'read() = print(open( 'xxx\xa 'read() = import glob glob glob('*\ *'['xxxy='glob glob( '*\xa *'[ 'xxx\xa 'non-ascii filename writes five characters textauto-encoded bytespre-encoded filename expansion tool get decoded text for decoded text get encoded bytes for encoded bytes stream contentpythonioencoding in additionthe environment variable pythonioencoding can be used to set the encoding used for text in the standard streams--inputoutputand error this setting overrides python' default encoding for printed textwhich on windows currently uses winusing unicode files