Skip to content

Commit 1fb3ae2

Browse files
committed
refactor: reconfigure sys.stdout/sys.stderr to force using UTF-8 encoding
1 parent dad7050 commit 1fb3ae2

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

python/pythonmonkey/require.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@
4444

4545
# Force to use UTF-8 encoding
4646
# Windows may use other encodings / code pages that have many characters missing/unrepresentable
47-
# Error: Python UnicodeEncodeError: 'charmap' codec can't encode characters in position ##-##: character maps to <undefined>
48-
sys.stdin = io.TextIOWrapper(sys.stdin .buffer, encoding='utf-8')
49-
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
50-
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
47+
# Error: Python UnicodeEncodeError: 'charmap' codec can't encode characters in position xx-xx: character maps to <undefined>
48+
sys.stdout.reconfigure(encoding='utf-8')
49+
sys.stderr.reconfigure(encoding='utf-8')
5150

5251
# Add some python functions to the global python object for code in this file to use.
5352
globalThis = pm.eval("globalThis;", evalOpts)

0 commit comments

Comments
 (0)