Although Python 3.8 should use UTF-8 also on Windows (PEP-0528 PEP-0529), one still gets
UnicodeEncodeError: 'charmap' codec can't encode character '\u251c' in position 0: character maps to <undefined>
The exception happens in cp1252.py
.
Example code (t.py
):
print(b'\xe2\x94\x9c'.decode('utf-8'))
print(b'\xe2\x94\x94'.decode('utf-8'))
print(b'\xe2\x94\x80'.decode('utf-8'))
print(b'\xe2\x94\x82'.decode('utf-8'))
It does not happen with python t.py
,
but it happens when piping
python t.py | python -c "import sys; print(sys.stdin.read())"
or forwarding to a file (python t.py > t.txt
).