Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode decode error [backport to 1.4.x] #3594

Merged
merged 2 commits into from
Sep 30, 2014
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def _get_home():
http://mail.python.org/pipermail/python-list/2005-February/325395.html
"""
try:
path = os.path.expanduser("~")
path = os.path.expanduser(b"~").decode(sys.getfilesystemencoding())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a tad confused why this goes through a byte string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 9/29/2014 20:42, Thomas A Caswell wrote:

In lib/matplotlib/init.py:

@@ -523,7 +523,7 @@ def _get_home():
http://mail.python.org/pipermail/python-list/2005-February/325395.html
"""
try:

  •    path = os.path.expanduser("~")
    
  •    path = os.path.expanduser(b"~").decode(sys.getfilesystemencoding())
    

I am a tad confused why this goes through a byte string


Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/3594/files#r18174163.

I got the idea from a comment in this thread:
https://stackoverflow.com/questions/23888120/an-alternative-to-os-path-expanduser

If I correctly understand what is happening because I pass in b""
expanduser returns a byte string, this can then be decoded using the
filesystemencoding, if u"
" or just "~" is used then expanduser will
convert using the sys.defaultencoding.

Hopefully someone with more Python know how then me can confirm that
this is a valid approach - at least on Windows.

except ImportError:
# This happens on Google App Engine (pwd module is not present).
pass
Expand Down