python - 如何在 python 2.4 中检查 UTF-8 编码数据(字节)
问题描述
在更高版本的python中,我可以这样做:
isinstance(s_out, bytes)
python2.4 中没有“字节”。在 python2.4 中是否有类似的方法也适用于所有其他 python 版本?
解决方案
import sys
if sys.version_info < (2, 7):
bytes = str
if isinstance(s_out, bytes):
我真的不知道上下文,但至少升级到 python 2.7 并且不浪费时间尝试使代码 python 2.4 兼容不是更好。
我不知道目标系统和操作系统,但可以想象可以安装更新的 python 并花时间使代码与更新的 python 一起工作。
推荐阅读
- asp.net-core - 在 TempData 中存储列表引发异常
- python - 如何在 $PATH 中获取 flake8
- ios - 使用 swift 可编码时处理不可预测的 json 响应
- php - HTML - 如何限制选择日期输入的天数?
- asp.net-mvc - 如何使用ajax(mvc)获取特定字段的下拉值
- ios - 无法将自定义单元格与 UITableView 一起使用
- java - StaggeredGridLayoutManager:添加Margin使布局项推到一边
- php - 未定义变量 当值为空时
- optaplanner - 员工排班示例的编辑规则
- css - 量角器图像没有上传到对话框?