我想将多个Python数组写入txt文件,每行一个数组。之后,我想逐行阅读Arrays。
我的正在进行的代码如下。我正在研究的问题涉及大约100,000个数组(L的长度)
from __future__ import division
from array import array
M = array('I',[1,2,3])
N = array('I',[10,20,30])
L = [M,N]
with open('manyArrays.txt','w') as file:
for a in L:
sA = a.tostring()
file.write(sA + '\n')
with open('manyArrays.txt','r') as file:
for line in file:
lineRead = array('I', [])
lineRead.fromstring(line)
print MRead
我收到的错误消息是
lineRead.fromstring(line)
ValueError: string length not a multiple of item size