标题: 使用python语言的struct模块转换字节流 [打印本页] 作者: kc_hxd_jp 时间: 2011-10-14 15:34 标题: 使用python语言的struct模块转换字节流 在文档上http://docs.python.org/library/struct.html#module-struct,这里提示使用格式化 ? 代表python的bool类型,但是在实际中报错
>>> str = struct.pack('?', True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\python25\lib\struct.py", line 62, in pack
o = _compile(fmt)
File "c:\python25\lib\struct.py", line 39, in _compile
s = Struct(fmt)
struct.error: bad char in struct format
>>>
为什么?作者: noword2k 时间: 2011-10-14 18:00
Notes:
The '?' conversion code corresponds to the _Bool type defined by C99. If this type is not available, it is simulated using a char. In standard mode, it is always represented by one byte.