Skip to content

Commit 19f04e5

Browse files
Merge pull request #142 from Distributive-Network/Xmader/fix/textio
fix: stdio stream objects may be monkeypatched at runtime not being instances of TextIOWrapper
2 parents 973fd21 + cd453af commit 19f04e5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

python/pythonmonkey/require.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545

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

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

0 commit comments

Comments
 (0)