How to detect EOF using numpy.fromfile

I am trying to read in a very large (several GB) binary with numpy.fromfile (). Reading in the entire file immediately generates an error from memory, so I want to create a loop to read and process N pieces of data at a time. Something like the following:

while True:
   numpy.fromfile(f, recordType, N)
   # proccess data 
   if f.EOF():
        break

How to determine when I reached the end of a file so that I can break my loop?

+4
source share
1 answer
while True:
   a = numpy.fromfile(f, recordType, N)
   # proccess data 
   if a.size < N:
        break
+1
source

Source: https://habr.com/ru/post/1682269/


All Articles