os.walk returns differently encoded non-ascii (unicode) filenames, how to deal with it?

Viewed 158

Exactly the same code, ran on Mac OsX and CentOS 7 return different results:

>>> path = u'examples'
>>> import os
>>> walker = os.walk(path, followlinks=True)
>>> list(walker)

On CentOS:

[u'filename-with-un\xec\u010d\xf8\u0111e-chars.txt', ... ]

On MacOSX:

[u'filename-with-uni\u0300c\u030c\xf8\u0111e-chars.txt', ... ]

BTW, The actual file name is filename-with-unìčøđe-chars.txt

What causes this behaviour, and how can we avoid it?

1 Answers
Related