How can I display native accents to languages in console in windows?

后端 未结 3 1257
别那么骄傲
别那么骄傲 2020-12-11 23:40
print \"Español\\nPortuguês\\nItaliano\".encode(\'utf-8\')

Errors:

Traceback (most recent call last): File \"\", line 1,

3条回答
  •  再見小時候
    2020-12-12 00:09

    First of all, in Python 2.x you can't encode a str that has non-ASCII characters. You have to write

    print u"Español\nPortuguês\nItaliano".encode('utf-8')
    

    Using UTF-8 at the Windows console is difficult.

    • You have to set the Command Prompt font to a Unicode font (of which the only one available by default is Lucida Console), or else you get IBM437 encoding anyway.
    • chcp 65001
    • Modify encodings._aliases to treat "cp65001" as an alias of UTF-8.

    And even then, it doesn't seem to work right.

提交回复
热议问题