Skip to content

Py2/3 兼容策略 ​

myhexdump 在 Python 2 与 Python 3 间兼容的策略汇总。

详见 dehex 与 Py2/3 兼容。本页为索引与总结。

核心开关 ​

python
PY3K = sys.version_info >= (3, 0)

主要兼容点 ​

场景Py2Py3
字符串模型str = 字节串str = unicode, bytes = 字节串
hex 字符串生成hexlify 返回 strhexlify 返回 bytes,需 decode
hex 还原.decode('hex')bytes.fromhex()
Windows stdout默认文本模式默认文本模式

相关文档 ​

基于 VitePress 构建 · 教学用途