2024-04-20 11:54:11 发布
网友
我想知道是否有一种简单的方法可以使用h5py检查HDF5文件中是否存在节点。
我在文档中找不到任何东西,所以现在我正在使用异常,这很难看。
# check if node exists # first assume it exists e = True try: h5File["/some/path"] except KeyError: e = False # now we know it doesn't
添加上下文:在尝试创建同名的新节点之前,我将使用此选项来确定节点是否存在。
e = "/some/path" in h5File
做到了。这在the ^{} documentation中非常简短地提到。
您还可以简单地对组使用require_group()方法。H5py Docs.
require_group()
在group docs检查文档之后。我假设您可以在使用前使用group对象的keys方法进行检查:
# check if node exists # first assume it doesn't exist e = False node = "/some/path" if node in h5file.keys(): h5File[node] e = True
做到了。这在the ^{} documentation 中非常简短地提到。
您还可以简单地对组使用
require_group()
方法。H5py Docs.在group docs检查文档之后。我假设您可以在使用前使用group对象的keys方法进行检查:
相关问题 更多 >
编程相关推荐