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
decode the execution path string based file system encoding #4343
Conversation
When my py file importing matplotlib run in a folder where the path contains gbk encoding character, matplotlib will raise a unicode decode error.The changes in line 666/673/679 will fix the problem.
fix support for python version 3+ and pep8
pep8 need some spaces around operator
What OS are you on? Can you turn that pattern into a helper function? attn @mdboom Checking for the decode attribute and assuming that it is encoded and making assumptions about what that encoding is seems sketchy to me, is there a better way to do this? |
The issue here is that we take the a path we get from Python and get a byte string back. Using that byte string to open the file again would be totally fine and correct. The problem is that we tack other things onto that path using a unicode string -- So, I think what this PR is doing is fine in general. However, I agree there should be a helper function for this, maybe |
My working OS is windows 7 Chinese version, the default file system encoding is gbk. Python 2.X can not detect the encoding correctly, and Matplotlib works well when the path only contains english chars, while not working when the path has any non-ascii chars like 中文. Using a helper function isinstance(obj, bytes) make the codes more readable and reliable. Thanks for the reminder. |
Change to using a helper function and isinstance(path, bytes) to decode __file__ based on file system encoding.
Oops, some white spaces.
FIX : decode the execution path string based file system encoding Prevents issues on systems with mixed encodings.
@sohero Thank you! I believe this is your first mpl contribution, congratulations. |
When my py file importing matplotlib run in a folder where the path contains gbk encoding character, matplotlib will raise a unicode decode error.The changes in line 666/673/679 will fix the problem.