I'm trying to pluck values out of many HDF5 files and store in a list.
import h5py
h = [h5py.File('filenum_%s.h5' % (n),'r')['key'][10][10] for n in range(100)]
This list comprehension contains the values at grid point (10, 10) in the 'key' array from the HDF5 files filenum0.h5
-filenum99.h5
.
It works, except that it stops around the 50th element with the error:
IOError: unable to open file (File accessibilty: Unable to open file)
even though I know the file exists and it can be opened if I haven't opened many other files. I think I get the error because too many files have been opened.
Is there a way to close the files within this list comprehension? Or, is there a more effective way to build the list I want?