Uh oh!
There was an error while loading. Please reload this page.
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.
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'
Uh oh!
There was an error while loading. Please reload this page.
huseyinacacak-janea
commented
Mar 13, 2024
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. |
* lib: print Python executable path using UTF-8 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: #2829 * fixup! lib: print Python executable path using UTF-8
Checklist
npm install && npm run lint && npm testpassesDescription 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