小编Dan*_*use的帖子

解决不同版本的Python bug

我在这个bytearray.fromhex函数中遇到了Python中的错误(至少在2.6.1中).如果您尝试使用docstring中的示例,则会发生以下情况:

>>> bytearray.fromhex('B9 01EF')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: fromhex() argument 1 must be unicode, not str
Run Code Online (Sandbox Code Playgroud)

这个例子在Python 2.7中运行良好,我想知道编码问题的最佳方法.我不想总是转换为unicode,因为它是性能损失,并且测试使用哪个Python版本感觉不对.

那么是否有更好的方法来编码这类问题,以便它适用于所有版本,最好不要为工作的Pythons减慢速度?

python python-2.6 python-2.7

5
推荐指数
1
解决办法
2075
查看次数

标签 统计

python ×1

python-2.6 ×1

python-2.7 ×1