当 mode != 'r' 时,即使超出文件末尾的正偏移量也是有效的;
fmt = "IIiiIIddiIiii64sIIII48sxxxx"
fmt1 = "?Idd16s"
file = open(self.resultName, "wb")
file.write(struct.pack(fmt, *self.header))
for i in range(someVar):
file.write(struct.pack(fmt1, *self.arr2[i]))
file.flush()
file.close
wave = np.memmap(self.resultName, dtype = np.uint16, mode = "r+", offset = 1024)
上面的代码会产生一个错误:
File "C:\Python\Python38\lib\site-packages\numpy\core\memmap.py", line 266, in __new__
self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm,
ValueError: negative dimensions are not allowed
如果偏移被移除,则没有错误。
有人有问题吗?你是怎么解决的?
谢谢