【问题标题】:How do I check for UTF-8 encoded data (bytes) in python 2.4如何在 python 2.4 中检查 UTF-8 编码数据(字节)
【发布时间】:2019-11-19 19:17:32
【问题描述】:

在更高版本的python中我可以做到:

isinstance(s_out, bytes)

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

【问题讨论】:

    标签: python python-2.x python-2.4


    【解决方案1】:
    import sys
    
    if sys.version_info < (2, 7):
        bytes = str
    
    
    if isinstance(s_out, bytes):
    

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

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

    【讨论】:

    • 鉴于 Python 2.7 支持在今年年底完全失效(不再提供修复,甚至安全修复),即使升级到 2.7 也不是什么解决方案,尽管总比没有好。
    • 工作,谢谢。长期修复是升级python。短期内需要使某些包向后兼容以防止出血。
    猜你喜欢
    • 2010-10-26
    • 2019-09-15
    • 2020-07-17
    • 2013-02-05
    • 2011-10-06
    • 1970-01-01
    • 1970-01-01
    • 2017-02-04
    • 1970-01-01
    相关资源
    最近更新 更多