Python 3.7+ cannot print unicode characters when output is redirected to file - is this a bug?
Barry
barry at barrys-emacs.org
Sun Nov 13 10:37:39 EST 2022
> On 13 Nov 2022, at 14:52, Jessica Smith <12jessicasmith34 at gmail.com> wrote:
>
> 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?
Your other thread has a reply that explained this.
It is a problem with windows and character sets.
You have to set things up to allow Unicode to work.
Barry
>
> Jessica
> --
> https://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list