gpt4 book ai didi

python - 控制字符的 CP437 解码是否损坏?

转载 作者:太空宇宙 更新时间:2023-11-03 14:49:28 26 4
gpt4 key购买 nike

根据Wikipedia page for Code Page 437字节值 \x01\x1f 应该解码为图形字符,例如b'\x01' 等同于 ☺ '\u263A'。但这不是 decode 产生的结果:

>>> b'\x01'.decode('cp437')
'\x01'

那是 Python 3.6,但 2.7 对所有 31 字节值执行相同的操作。

最佳答案

虽然有与 \x01\x1f 字节范围相关联的图形,但这些图形仅在某些上下文中使用。在其他情况下,这些代码点将被解释为控制字符,如在 ASCII 中一样。引用 IBM page on CP437 :

Code points X'01' through X'1F' and X'7F' may be controls or graphics depending on context. For displays the hexadecimal code in a memory-mapped video display buffer is a graphic. For printers the graphics context is established by a preceding control sequence in the data stream. There are two such control sequences: ESC X'5C' and ESC X'5E' named Print All Characters and Print Single Character respectively. In other situations the code points in question are used as controls.

Python的CP437解码是基于Unicode mappings on Unicode.org , 使用控制字符解释。

Unicode FAQ implies “CP437 和其他 DOS 类型代码页的特殊图形字符(01-1F、7F)的正确 Unicode 映射”应该在 https://www.unicode.org/Public/MAPPINGS 上可用。 , 但在那里挖掘只会发现带有控制字符的映射,以及 page链接到多个 IBM 网站。挖掘 IBM 的网站会发现 ftp://ftp.software.ibm.com/software/globalization/gcoc/attachments/CP00437.txt , 它根据 IBM 的 GCGID system 给出了 \x01-\x1f 的图形映射,但不是根据 Unicode。

我不知道是否真的来自 IBM 或 Unicode 的官方映射,它为 \x01-\x1f 提供规范的 Unicode 映射 根据 CP437 的图形解释。

关于python - 控制字符的 CP437 解码是否损坏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46942721/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com