Skip to content

Instantly share code, notes, and snippets.

@adiroiban adiroiban/test.py
Created Apr 8, 2015

Embed
What would you like to do?
Unicode os.stat
-> os.stat(path)
(Pdb) path
u'/tmp/4b385cfb-f96c-4eca-81c9-70d1223353d6-cp\u021b/3741-cp\u021baaaaaaaaaaaaaaaaaaaaaaaa'
(Pdb) os.stat(path)
*** UnicodeEncodeError: 'ascii' codec can't encode character u'\u021b' in position 44: ordinal not in range(128)
(Pdb) os.stat(path.encode('utf-8'))
*** OSError: [Errno 2] No such file or directory: '/tmp/4b385cfb-f96c-4eca-81c9-70d1223353d6-cp\xc8\x9b/3741-cp\xc8\x9baaaaaaaaaaaaaaaaaaaaaaaa'
(Pdb) os.environ.get('LANG')
'C'
(Pdb) os.stat(path)
*** UnicodeEncodeError: 'ascii' codec can't encode character u'\u021b' in position 44: ordinal not in range(128)
(Pdb) sys.getfilesystemencoding()
'ANSI_X3.4-1968'
(Pdb) os.environ['LANG'] = 'C'
(Pdb) sys.getfilesystemencoding()
'ANSI_X3.4-1968'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.