我有大约 1300 个 h5 文件可以使用 h5py 排序到字典中。当我在大约 250 个文件上运行我的代码时,它工作正常,但是任何更大的文件都会给我错误:
Traceback (most recent call last):
File "solution_script.py", line 31, in <module>
File "build/bdist.macosx-10.7-intel/egg/h5py/_hl/files.py", line 165, in __init__
File "build/bdist.macosx-10.7-intel/egg/h5py/_hl/files.py", line 57, in make_fid
File "h5f.pyx", line 70, in h5py.h5f.open (h5py/h5f.c:1626)
IOError: unable to open file (File accessability: Unable to open file)'
我不确定我是否错误地设置了字典,或者是否有更好的方法来做到这一点。
如果有人能看到我犯的一些明显错误,这是我的代码:
nodesDictionary = {}
velDictionary = {}
cellsDictionary={}
num_h5file = -1;
for root, directory, files in os.walk(rootDirectory):
for file in sorted(files):
if file.endswith(".h5"):
num_h5file = num_h5file + 1
curh5file = h5py.File(file, 'r')
nodes_list = curh5file["nodes"]
cells_list = curh5file["cells"]
velocity_list = curh5file["velocity"]
for i in range(0, len(nodes_list)-1):
if num_h5file not in nodesDictionary:
nodesDictionary[num_h5file] = [curh5file["nodes"][i]]
velDictionary[num_h5file] = [curh5file["velocity"][i]]
else:
nodesDictionary[num_h5file].append(curh5file["nodes"][i])
velDictionary[num_h5file].append(curh5file["velocity"][i])
for j in range(0, len(cells_list)-1):
if num_h5file not in cellsDictionary:
cellsDictionary[num_h5file] = [curh5file["cells"][j]]
else:
cellsDictionary[num_h5file].append(curh5file["cells"][j])
任何帮助/建议/见解将不胜感激:)