我已经确定了字符串是剥离,我仍然得到奇数长度字符串问题。有人能告诉我我做错了什么吗?
>>> toSend = "FF F9 FF 00 00 FA FF F7 FF F4 FF F6 FF F7 FF F6 FF FD FF 05 00 03 00 06 00 05 00 04 00 06 00 06 00 03 00 FB FF 02 00 0B"
>>> toSend.decode("hex")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/encodings/hex_codec.py", line 42, in hex_decode
output = binascii.a2b_hex(input)
TypeError: Odd-length string
>>>
字符串中的空格混淆了
decode
方法。如果删除它们,代码将正常工作:或者,如果必须拥有它们,请使用
str.join
和列表理解:相关问题 更多 >
编程相关推荐