繁体   English   中英

使用Python的struct包将二进制文件读入布尔数组

[英]Reading a binary file into a boolean array using Python's struct package

我试图将一个二进制文件(只有32位长)读入一个布尔数组。 当我遵循时,它工作得很好:

使用Python如何读取字节中的位?

但是,当我尝试使用struct包时,会得到不同的结果:

_fmt = '32?'

with open(filename, mode='rb') as fp:
    content = struct.unpack(fmt, fp.read(struct.calcsize(fmt))

我想知道为什么。

谢谢

格式为“ '32?' 表示32个字节,而不是32位。

位数组可能会帮助您: http ://pypi.python.org/pypi/bitarray

或这里的食谱: http : //wiki.python.org/moin/BitArrays

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM