简体   繁体   English

如何在 python 2.4 中检查 UTF-8 编码数据(字节)

[英]How do I check for UTF-8 encoded data (bytes) in python 2.4

In higher versions of python i can do:在更高版本的 python 我可以这样做:

isinstance(s_out, bytes)

There is no 'bytes' in python2.4. python2.4 中没有“字节”。 Is there an equivalent of doing this in python2.4 which also works for all other python versions?在 python2.4 中是否有类似的方法,它也适用于所有其他 python 版本?

import sys

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


if isinstance(s_out, bytes):

I really don't know the context but wouldn't it better to upgrade at least to python 2.7 and not lose time trying to make code python 2.4 compatible.我真的不知道上下文,但最好至少升级到 python 2.7 并且不要浪费时间尝试使代码 python 2.4 兼容。

I do not know the target systems and the OS, but could imagine that it is possible to install a more recent python and invest the time to make the code work with newer pythons.我不知道目标系统和操作系统,但可以想象可以安装更新的 python 并花时间使代码与更新的 python 一起工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM