R. David Murray added the comment:

On linux as well this fails:

  os.path.expanduser(u'~' + os.sep)

But this works:

  os.path.expanduser('~' + os.sep)

Counterintuitive, to say the least.  The reason is that the value of the HOME 
environment variable is read as a byte string, but when that byte string value 
is added to the unicode u'~/', unicode coercion attempts to decode the byte 
string as an ASCII string, which fails.

So, you must manipulate paths as byte strings in python2, decoding them 
yourself with the appropriate codec if needed.

This stuff is handled automatically in Python3, using the default encoding as 
you suggest (plus the surrogateescape error handler to handle unknown bytes on 
linux/unix).  Fixes for stuff like this is a large part of the purpose of 
Python3.  

So, in Python2 this is working as expected.

----------
resolution:  -> invalid
stage:  -> committed/rejected
status: open -> closed
type:  -> behavior

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18171>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to