【问题标题】:Python: block character will not printPython:块字符不会打印
【发布时间】:2012-10-02 23:19:03
【问题描述】:

在 IDLE 中,print(chr(219))(219 的块字符)输出“Û”。

有没有办法让它输出块字符呢?

这实际上可能是某种计算机范围的问题,因为我似乎无法从任何地方打印块字符,将其从charmap复制到 any 文本框只会导致 Û .

【问题讨论】:

    标签: python character-encoding ascii block non-ascii-characters


    【解决方案1】:

    使用正确的字符集。

    3>> print(bytes((219,)).decode('cp437'))
    █
    3>> ord(bytes((219,)).decode('cp437'))
    9608
    3>> hex(9608)
    '0x2588'
    3>> print('\u2588')
    █
    

    Unicode Character 'FULL BLOCK' (U+2588)

    【讨论】:

      【解决方案2】:

      您的 python shell 可能使用 ISO-8859-1 或 Unicode,而不是与字符映射相同的字符集。

      chr(219) 也是 U+00DB,可能是 Unicode 字符 Û。我不知道您使用的是什么字符集,但在 Unicode 字符集的早期没有任何符号字符。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-07-11
        • 2021-04-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-17
        • 1970-01-01
        相关资源
        最近更新 更多