Python 3.7+ cannot print unicode characters when output is redirected to file - is this a bug?
Jessica Smith
12jessicasmith34 at gmail.com
Sun Nov 13 09:49:40 EST 2022
Consider the following code ran in Powershell or cmd.exe:
$ python -c "print('└')"
└
$ python -c "print('└')" > test_file.txt
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program Files\Python38\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2514' in
position 0: character maps to <undefined>
Is this a known limitation of Windows + Unicode? I understand that
using -x utf8 would fix this, or modifying various environment
variables. But is this expected for a standard Python installation on
Windows?
Jessica
More information about the Python-list
mailing list