Python数组:强制'l'长4个字节

时间:2017-09-02 15:56:01

标签: python arrays binaryfiles long-integer

我有biary文件,标头+ 4字节长整数值的集合。

struct.unpack解压缩标头后,我创建剩余值的数组。

int_values = array.array('l')
int_values.fromfile(binary_input, self.columns * self.rows)

在Windows下,一切都按预期工作。 在我的Linux(Ubuntu 12.04)下,我收到以下错误:

int_values.fromfile(byn_input, self.columns * self.rows)
EOFError: not enough items in file

默认情况下,似乎Ubuntu 'l'下的长度为8个字节。 使用struct,我可以通过前缀'=, <, >, !'

声明模式

我怎么能强制array('l')长4个字节,尽管默认为8个字节?

0 个答案:

没有答案