-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
lib: print Python executable path using UTF-8 #2995
lib: print Python executable path using UTF-8 #2995
Conversation
The Python executable path may have non-ASCII characters, which can make the print function fail if the environment encoding is different. This fixes this issue by using stdout.buffer, which can be used with UTF-8 encoding for the output, regardless of the environment encoding. Fixes: nodejs#2829
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the Python REPL, can you create an example where print()
fails but sys.stdout.buffer.write()
succeeds?
% python3
>>> import sys
>>> msg = "Héllø"
>>> print(msg)
Héllø
>>> sys.stdout.buffer.write(msg.encode("utf-8"))
Héllø7
>>> msg.encode("utf-8")
b'H\xc3\xa9ll\xc3\xb8'
Here is my example REPL.
This PR aims to print the executable with UTF-8 encoding, regardless of the environment encoding. As my environment is UTF-8 by default, I forced it to change the encoding in REPL by adding the line: |
Nice example! Thanks... The trailing digit worried me, but now I see it is the return value of the number of bytes written.
|
Checklist
npm install && npm run lint && npm test
passesDescription of change
The Python executable path may have non-ASCII characters, which can make the print function fail if the environment encoding is different. This PR fixes this issue by using
stdout.buffer
, which can be used with UTF-8 encoding for the output, regardless of the environment encoding.Fixes: #2829
Refs: #2987