Py2/3 兼容策略
myhexdump 在 Python 2 与 Python 3 间兼容的策略汇总。
详见 dehex 与 Py2/3 兼容。本页为索引与总结。
核心开关
python
PY3K = sys.version_info >= (3, 0)主要兼容点
| 场景 | Py2 | Py3 |
|---|---|---|
| 字符串模型 | str = 字节串 | str = unicode, bytes = 字节串 |
| hex 字符串生成 | hexlify 返回 str | hexlify 返回 bytes,需 decode |
| hex 还原 | .decode('hex') | bytes.fromhex() |
| Windows stdout | 默认文本模式 | 默认文本模式 |