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
@mcepl
Copy link

mcepl commented Apr 29, 2014

Works for me.

matej@wycliff: rendercheck (master *%)$ python3
Python 3.3.2 (default, Nov 19 2013, 08:35:03) 
[GCC 4.8.2 20131106 (Red Hat 4.8.2-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> letter = '\xf6'
>>> letter
'ö'
>>> open(letter, 'w').close()
>>> os.listdir('.')
['.git', '.gitignore', 'rendercheck-589bb58df06f6cf3b5e92c05f8cf6f997f31ab12.tar.gz', 'rendercheck-1.4-1.0.20140402GIT589bb58.el7.src.rpm', 'ö', 'rpmbuild-log.txt', 'rendercheck-589bb58df06f6cf3b5e92c05f8cf6f997f31ab12', 'x86_64', 'rendercheck.spec', 'Makefile']
>>> os.listdir('.')[4]
'ö'
>>> os.listdir('.')[4] == letter
True
>>> 

That's RHEL-7 (package from Fedora 21)

@fdemmer
Copy link

fdemmer commented Apr 29, 2014

working on ubuntu trusty with Python 3.4.0 (default, Apr 11 2014, 13:05:11), but i guess the whole point was, that python is not consistent on different platforms/distributions?

@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