首页 > 解决方案 > 如何在 python 2.4 中检查 UTF-8 编码数据(字节)

问题描述

在更高版本的python中,我可以这样做:

isinstance(s_out, bytes)

python2.4 中没有“字节”。在 python2.4 中是否有类似的方法也适用于所有其他 python 版本?

标签: pythonpython-2.xpython-2.4

解决方案


import sys

if sys.version_info < (2, 7):
    bytes = str


if isinstance(s_out, bytes):

我真的不知道上下文,但至少升级到 python 2.7 并且不浪费时间尝试使代码 python 2.4 兼容不是更好。

我不知道目标系统和操作系统,但可以想象可以安装更新的 python 并花时间使代码与更新的 python 一起工作。


推荐阅读