[Python] Wrong encoding with Python decode in Windows command prompt

Discussão em 'Python' iniciado por Stack, Maio 16, 2025.

  1. Stack

    Stack Membro Participativo

    When I run decode on a byte string encoded as UTF-8 I get ANSI encoding in a Windows command prompt.

    >python --version
    Python 3.13.0
    >python -c "print(b'\xc3\x96'.decode('utf-8'))" > test.txt


    When I open test.txt in Notepad++ it says that the encoding is ANSI. If I run the same command in MSYS2 (using Python 3.11.6) the resulting encoding is UTF-8 as expected. How come the encoding is wrong using the Windows command prompt?

    Continue reading...

Compartilhe esta Página