Python HDF5 H5Py issues opening multiple files

后端 未结 1 489
庸人自扰
庸人自扰 2020-12-21 01:17

I am usint the 64-bit version of Enthought Python to process data across multiple HDF5 files. I\'m using h5py version 1.3.1 (HDF5 1.8.4) on 64-bit Windows.

I have

相关标签:
1条回答
  • 2020-12-21 01:44

    I've concluded that this is a strange manifestation of Perplexing assignment behavior with h5py object as instance variable . I re-wrote my code so that each file is handled within a function call and the variable is not reused. Using this approach, I don't see the same strange behavior and it seems to work much better. For clarity, the solution looks more like:

    files = glob(r'path\*.h5')
    out_csv = csv.writer(open('output_file.csv', 'rb'))
    
    def extract_data_from_filename(filename):
        return extract_data_from_handle(hdf5.File(filename, 'r'))
    
    for filename in files:
      data = extract_data_from_filename(filename)
      for row in data:
         out_csv.writerow((filename, ) +row)
    
    0 讨论(0)
提交回复
热议问题