python - How do I fix this error? TypeError: 'str' does not support the buffer interface -
>>> import struct >>> s = '\x00\x00\x00\x01\x00\x00\x00\xff\xff\x00\x00' >>> struct.unpack('11b', s) traceback (most recent phone call last): file "<pyshell#3>", line 1, in <module> struct.unpack('11b', s) typeerror: 'str' not back upwards buffer interface
what wrong this? please help.
on python 3, struct.unpack()
expects object implements buffer protocol, such bytes
value, not unicode str
:
>>> import struct >>> s = b'\x00\x00\x00\x01\x00\x00\x00\xff\xff\x00\x00' >>> struct.unpack('11b', s) (0, 0, 0, 1, 0, 0, 0, 255, 255, 0, 0)
if reading info file, open file in binary mode instead of text mode bytes.
python string runtime-error
No comments:
Post a Comment