Append element to binary file

Viewed 2797

My goal is: Open a binary file, store (append) every 100 values into this file, and continue doing so until finishing. To do so, I use the following simple loop to simulate that:

import numpy as np
import random

alist=[]
c = 1

for i in range(1000):
    alist.append(i)
    if i == (c*100):
        np.array(alist).tofile("file.bin")
        print alist
        c = c + 1
        alist[:] = [] # clear the list before continuing

However, when I check the size of file.bin, I feel numpy does not append rather it is replacing which is not what I want. How to fix that?

Thank you.

1 Answers
Related