[SciPy-user] scipy.io.numpyio fwrite - appending or updating an array

Brennan Williams brennan.williams@visualreservoir....
Fri Aug 1 04:14:09 CDT 2008


I'll look into memmap as Stefan suggested. If Robert Kern's out there, 
do you have any comments about what I might be doing wrong.
Id on't know memmap at all yet - basically each file will have multiple 
numpy arrays written, read, appended and updated as required.

Brennan

Brennan Williams wrote:
> I've tried replacing numpyio with both fopen and now also npfile but I'm 
> getting the same problem, i.e. if I write a numpy array to the file,
> everything else before that position in the file is now zero. It is as 
> if it is a new file, not an existing one.
>
> Brennan Williams wrote:
>   
>> I have an existing binary file containing numpy array data. It has been 
>> created using open,fwrite & close and I can read the data using fread.
>>
>> I want to be able to either append a new array to the end of the file or 
>> update an existing array within the file.
>>
>> I've tried opening the file with a mode of either 'ab+' or 'wb+' and 
>> then writing the data using something like....
>>
>>      fd = open(vfname, 'ab+')
>>      if fd:
>>        filepos=(self.id-1)*self.yarray.size*4
>>        fd.seek(filepos)
>>        fwrite(fd, self.yarray.size, self.yarray,'f')
>>        fd.close()
>>
>> When I use a mode of 'ab+' it looks like the data has been written to 
>> the file ok (no errors reported) but when I read it back I get my 
>> original data.
>>
>> When I use 'wb+' then my updated data gets written and read back ok. But 
>> when I reload the file, everything apart from my updated data (i.e. 
>> everything before it in the file) is now zero.
>>
>> The '+' in the mode seems to make no difference.
>>
>> What am I doing wrong?
>>
>> Thanks
>>
>> Bren.
>> _______________________________________________
>> SciPy-user mailing list
>> SciPy-user@scipy.org
>> http://projects.scipy.org/mailman/listinfo/scipy-user
>>
>>   
>>     
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
>   



More information about the SciPy-user mailing list