当data1不在file_i.hdf5中时:
KeyError: "unable to open object (Symbol table: Can't open object)"
答案 0 :(得分:1)
使用try:
和except(KeyError):
来捕获异常,如此。
import h5py
for i in range(0,100):
try:
with h5py.File('file_%s.hdf5' % i) as f:
my_data = f['data1'][:]
print i
except(KeyError):
# more code goes here...