Skip to content

Instantly share code, notes, and snippets.

@mitsuhiko
Created April 29, 2014 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitsuhiko/11395418 to your computer and use it in GitHub Desktop.
Save mitsuhiko/11395418 to your computer and use it in GitHub Desktop.
mitsuhiko at atherton in /tmp/test
$ python3
Python 3.4.0 (v3.4.0:04f714765c13, Apr 15 2014, 15:41:42)
[GCC 4.2.1 Compatible Clang 3.2 (tags/RELEASE_32/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> letter = '\xf6'
>>> letter
'ö'
>>> open(letter, 'w').close()
>>> os.listdir('.')[0]
'ö'
>>> os.listdir('.')[0] == letter
False
@SimonSapin
Copy link

This is OS X’s filesystem doing Unicode normalization.

@acdha
Copy link

acdha commented Apr 29, 2014

This has always been buggy code – OS X normalizes to NFD, Linux is usually NFC and Windows does neither (“the file system treats path and file names as an opaque sequence of WCHARs” – http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx).

@sassman
Copy link

sassman commented May 1, 2014

it works on Arch with
Python 3.4.0 (default, Mar 17 2014, 23:20:09)
[GCC 4.8.2 20140206 (prerelease)] on linux

cat /etc/locale.conf
LANG=en_US.UTF-8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment